Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <array>
- #include <bitset>
- #include <cassert>
- #include <chrono>
- #include <climits>
- #include <cmath>
- #include <complex>
- #include <cstring>
- #include <functional>
- #include <iomanip>
- #include <iostream>
- #include <map>
- #include <numeric>
- #include <queue>
- #include <random>
- #include <set>
- #include <vector>
- using namespace std;
- #define ll long long
- #define forn(i, s, n) for (int i = s; i < n; i++)
- #define bforn(i, s) for (int i = s; i >= 0; i--)
- // for pairs
- #define s second
- #define f first
- const int M = 2e5 + 1;
- const char nl = '\n';
- char g[1002][1002];
- int newDir(int i, int j, int dir){
- if (g[i][j] == '/'){
- if (dir == 1) dir = 4;
- else if (dir == 2) dir = 3;
- else if (dir == 3) dir = 2;
- else dir = 1;
- }
- if (g[i][j] == '\\'){
- if (dir == 1) dir = 3;
- else if (dir == 2) dir = 4;
- else if (dir == 3) dir = 1;
- else dir = 2;
- }
- return dir;
- }
- void solve(){
- int n, m; cin >> n >> m;
- fill(g[0], g[0] + m + 1, '-');
- fill(g[n + 1], g[n + 1] + m + 1, '-');
- for (int i = 1; i <= n; i++){
- for (int j = 0; j <= m + 1; j++){
- if (j == 0 || j == m + 1){
- g[i][j] = '-';
- continue;
- }
- cin >> g[i][j];
- }
- }
- int dir = 2;
- int ans = 0;
- for (int col = 1; col <= n; col++){
- int i = col, j = 1;
- int r = 0;
- dir = 2;
- while (g[i][j] != '-'){
- dir = newDir(i, j, dir);
- if (dir == 1) j--;
- if (dir == 2) j++;
- if (dir == 3) i--;
- if (dir == 4) i++;
- r++;
- //cout << i << ' ' << j << nl;
- }
- //cout << nl;
- ans = max(ans, r);
- }
- //cout << ans << nl;
- for (int col = 1; col <= n; col++){
- int i = col, j = m;
- int r = 0;
- dir = 1;
- while (g[i][j] != '-'){
- dir = newDir(i, j, dir);
- if (dir == 1) j--;
- if (dir == 2) j++;
- if (dir == 3) i--;
- if (dir == 4) i++;
- r++;
- }
- ans = max(ans, r);
- }
- //cout << ans << nl;
- for (int row = 1; row <= m; row++){
- dir = 4;
- int i = 1, j = row;
- int r = 0;
- while (g[i][j] != '-'){
- dir = newDir(i, j, dir);
- if (dir == 1) j--;
- if (dir == 2) j++;
- if (dir == 3) i--;
- if (dir == 4) i++;
- r++;
- }
- ans = max(ans, r);
- }
- //cout << ans << nl;
- for (int row = 1; row <= m; row++){
- dir = 3;
- int i = n, j = row;
- int r = 0;
- while (g[i][j] != '-'){
- dir = newDir(i, j, dir);
- if (dir == 1) j--;
- if (dir == 2) j++;
- if (dir == 3) i--;
- if (dir == 4) i++;
- r++;
- }
- ans = max(ans, r);
- }
- cout << ans << nl;
- }
- // if you are unsure of how to do a problem by hand
- // the solution is most likely somewhat brute force (i.e binsearch)
- // if input is limited to 0-9 or a-z, usually you will loop through all combinations
- // of letters or numbers
- // constructive problems : start with 1 when constructing
- // :%y+ to copy all lines
- // rearrange math expressions
- // difference array? (a[i] - b[i])
- // debugging : reread the problem statement-every word is important!
- // debugging : print important variables!
- // think brute force sol first
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- freopen("mirror.in", "r", stdin);
- freopen("mirror.out", "w", stdout);
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement