Advertisement
a_chn

Untitled

Jan 17th, 2024
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | None | 0 0
  1. #include <algorithm>
  2. #include <array>
  3. #include <bitset>
  4. #include <cassert>
  5. #include <chrono>
  6. #include <climits>
  7. #include <cmath>
  8. #include <complex>
  9. #include <cstring>
  10. #include <functional>
  11. #include <iomanip>
  12. #include <iostream>
  13. #include <map>
  14. #include <numeric>
  15. #include <queue>
  16. #include <random>
  17. #include <set>
  18. #include <vector>
  19. using namespace std;
  20.  
  21. #define ll long long
  22. #define forn(i, s, n) for (int i = s; i < n; i++)
  23. #define bforn(i, s) for (int i = s; i >= 0; i--)
  24. // for pairs
  25. #define s second
  26. #define f first
  27. const int M = 2e5 + 1;
  28. const char nl = '\n';
  29.  
  30. char g[1002][1002];
  31.  
  32. int newDir(int i, int j, int dir){
  33.     if (g[i][j] == '/'){
  34.         if (dir == 1) dir = 4;
  35.         else if (dir == 2) dir = 3;
  36.         else if (dir == 3) dir = 2;
  37.         else dir = 1;
  38.     }
  39.     if (g[i][j] == '\\'){
  40.         if (dir == 1) dir = 3;
  41.         else if (dir == 2) dir = 4;
  42.         else if (dir == 3) dir = 1;
  43.         else dir = 2;
  44.     }
  45.     return dir;
  46. }
  47. void solve(){
  48.     int n, m; cin >> n >> m;
  49.     fill(g[0], g[0] + m + 1, '-');
  50.     fill(g[n + 1], g[n + 1] + m + 1, '-');
  51.     for (int i = 1; i <= n; i++){
  52.         for (int j = 0; j <= m + 1; j++){
  53.             if (j == 0 || j == m + 1){
  54.                 g[i][j] = '-';
  55.                 continue;
  56.             }
  57.             cin >> g[i][j];
  58.         }
  59.     }
  60.     int dir = 2;
  61.     int ans = 0;
  62.     for (int col = 1; col <= n; col++){
  63.         int i = col, j = 1;
  64.         int r = 0;
  65.         dir = 2;
  66.         while (g[i][j] != '-'){
  67.             dir = newDir(i, j, dir);
  68.             if (dir == 1) j--;
  69.             if (dir == 2) j++;
  70.             if (dir == 3) i--;
  71.             if (dir == 4) i++;
  72.             r++;
  73.             //cout << i << ' ' << j << nl;
  74.         }
  75.         //cout << nl;
  76.         ans = max(ans, r);
  77.     }
  78.     //cout << ans << nl;
  79.     for (int col = 1; col <= n; col++){
  80.         int i = col, j = m;
  81.         int r = 0;
  82.         dir = 1;
  83.         while (g[i][j] != '-'){
  84.             dir = newDir(i, j, dir);
  85.             if (dir == 1) j--;
  86.             if (dir == 2) j++;
  87.             if (dir == 3) i--;
  88.             if (dir == 4) i++;
  89.             r++;
  90.         }
  91.         ans = max(ans, r);
  92.     }
  93.     //cout << ans << nl;
  94.     for (int row = 1; row <= m; row++){
  95.         dir = 4;
  96.         int i = 1, j = row;
  97.         int r = 0;
  98.         while (g[i][j] != '-'){
  99.             dir = newDir(i, j, dir);
  100.             if (dir == 1) j--;
  101.             if (dir == 2) j++;
  102.             if (dir == 3) i--;
  103.             if (dir == 4) i++;
  104.             r++;
  105.         }
  106.         ans = max(ans, r);
  107.     }
  108.     //cout << ans << nl;
  109.     for (int row = 1; row <= m; row++){
  110.         dir = 3;
  111.         int i = n, j = row;
  112.         int r = 0;
  113.         while (g[i][j] != '-'){
  114.             dir = newDir(i, j, dir);
  115.             if (dir == 1) j--;
  116.             if (dir == 2) j++;
  117.             if (dir == 3) i--;
  118.             if (dir == 4) i++;
  119.             r++;
  120.         }
  121.         ans = max(ans, r);
  122.     }
  123.     cout << ans << nl;
  124. }
  125. // if you are unsure of how to do a problem by hand
  126. // the solution is most likely somewhat brute force (i.e binsearch)
  127. // if input is limited to 0-9 or a-z, usually you will loop through all combinations
  128. // of letters or numbers
  129. // constructive problems : start with 1 when constructing
  130. // :%y+ to copy all lines
  131. // rearrange math expressions
  132. // difference array? (a[i] - b[i])
  133. // debugging : reread the problem statement-every word is important!
  134. // debugging : print important variables!
  135. // think brute force sol first
  136. int main(){
  137.     ios::sync_with_stdio(false);
  138.     cin.tie(nullptr);
  139.     cout.tie(nullptr);
  140.     freopen("mirror.in", "r", stdin);
  141.     freopen("mirror.out", "w", stdout);
  142.     solve();
  143. }
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement