This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
using namespace std;
const int N = 4005, A[] = {1, -1, 0, 0}, B[] = {0, 0, 1, -1};
int n, m, a[N][N], u[N][N], ans = 1, cur;
deque <pair <int, int> > q;
inline bool check(int x, int y) {
return x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] != 2 && !u[x][y];
}
int main (){
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("\n");
for (int j = 1; j <= m; j++) {
char ch;
scanf("%c", &ch);
switch (ch) {
case 'F':
a[i][j] = 0;
break;
case 'R':
a[i][j] = 1;
break;
case '.':
a[i][j] = 2;
break;
default:
assert(0);
}
}
}
cur = a[1][1];
u[1][1] = 1;
q.push_back({1, 1});
while (!q.empty()) {
int x = q.front().fr, y = q.front().sc;
q.pop_front();
if (a[x][y] != cur)
ans++, cur ^= 1;
for (int i = 0; i < 4; i++) {
if (check(x + A[i], y + B[i])) {
u[x + A[i]][y + B[i]] = 1;
if (cur != a[x + A[i]][y + B[i]])
q.push_back({x + A[i], y + B[i]});
else
q.push_front({x + A[i], y + B[i]});
}
}
}
cout << ans << endl;
}
Compilation message (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("\n");
| ~~~~~^~~~~~
tracks.cpp:26:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%c", &ch);
| ~~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |