@@ -9,42 +9,42 @@ int visited[501][501], dx[4]{-1, -1, 1, 1}, dy[4]{-1, 1, -1, 1};
99pair<int , int > dz[4 ]{{-1 , -1 }, {-1 , 0 }, {0 , -1 }, {0 , 0 }};
1010
1111bool inside (int x, int y) {
12- return (~x && x <= n && ~y && y <= m);
12+ return (~x && x <= n && ~y && y <= m);
1313}
1414
1515int main () {
16- cin >> n >> m;
16+ cin >> n >> m;
1717
18- FOR (i, 0 , n) FOR (j, 0 , m) {
19- char c;
20- cin >> c;
21- if (c == orientation[(i + j) & 1 ]) correct[i][j] = true ;
22- else correct[i][j] = false ;
23- }
18+ FOR (i, 0 , n) FOR (j, 0 , m) {
19+ char c;
20+ cin >> c;
21+ if (c == orientation[(i + j) & 1 ]) correct[i][j] = true ;
22+ else correct[i][j] = false ;
23+ }
2424
25- deque<pair<int , pair<int , int >>> dq;
26- dq.push_back ({1 , {0 , 0 }});
27- while (dq.size ()) {
28- int x, y, z;
29- tie (x, y) = dq.front ().second ;
25+ deque<pair<int , pair<int , int >>> dq;
26+ dq.push_back ({1 , {0 , 0 }});
27+ while (dq.size ()) {
28+ int x, y, z;
29+ tie (x, y) = dq.front ().second ;
3030 z = dq.front ().first ;
31- dq.pop_front ();
31+ dq.pop_front ();
3232 if (visited[x][y]) continue ;
3333 visited[x][y] = z;
3434
35- FOR (i, 0 , 4 ) {
36- int nx = x + dx[i], ny = y + dy[i];
37- if (inside (nx, ny) && !visited[nx][ny]) {
38- if (correct[x + dz[i].first ][y + dz[i].second ]) {
39- dq.push_front ({z, {nx, ny}});
40- } else {
41- dq.push_back ({z + 1 , {nx, ny}});
42- }
43- }
44- }
45- }
35+ FOR (i, 0 , 4 ) {
36+ int nx = x + dx[i], ny = y + dy[i];
37+ if (inside (nx, ny) && !visited[nx][ny]) {
38+ if (correct[x + dz[i].first ][y + dz[i].second ]) {
39+ dq.push_front ({z, {nx, ny}});
40+ } else {
41+ dq.push_back ({z + 1 , {nx, ny}});
42+ }
43+ }
44+ }
45+ }
4646
47- if (visited[n][m]) cout << visited[n][m] - 1 ;
48- else cout << " NO SOLUTION" ;
49- return 0 ;
47+ if (visited[n][m]) cout << visited[n][m] - 1 ;
48+ else cout << " NO SOLUTION" ;
49+ return 0 ;
5050}
0 commit comments