#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int u[] = {0, 1, 0, -1};
const int v[] = {1 , 0, -1, 0};
const int N = 4055;
int W, H;
char snow[N][N];
bool safe(int u, int v)
{
return (u >= 0 && u < W && v >= 0 && v < H);
}
void solve()
{
cin >> W >> H;
for(int row=0; row<W; row++)
{
for(int col=0; col<H; col++)
{
cin >> snow[row][col];
}
}
queue<pair<int, int>> que[2];
int num = 0;
que[num & 1].push(make_pair(W - 1, H - 1));
char track = snow[W - 1][H - 1];
snow[W - 1][H - 1] = '#';
while(!que[num & 1].empty())
{
int rest = 1 - (num & 1);
int cur = num & 1;
while(!que[cur].empty())
{
pair<int, int> now = que[cur].front();
que[cur].pop();
int curU = now.fi, curV = now.se;
for(int i=0; i<4; i++)
{
int ux = curU + u[i], vx = curV + v[i];
if (safe(ux, vx))
{
if (snow[ux][vx] == track)
{
que[cur].push(make_pair(ux, vx));
snow[ux][vx] = '#';
} else
{
if (snow[ux][vx] != '.' && snow[ux][vx] != '#')
{
que[rest].push(make_pair(ux, vx));
snow[ux][vx] = '#';
}
}
}
}
}
track = (track == 'F' ? 'R' : 'F');
num++;
}
cout << num;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2516 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
7 ms |
2520 KB |
Output is correct |
5 |
Correct |
3 ms |
1544 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
1364 KB |
Output is correct |
11 |
Correct |
2 ms |
1104 KB |
Output is correct |
12 |
Correct |
5 ms |
1500 KB |
Output is correct |
13 |
Correct |
4 ms |
1500 KB |
Output is correct |
14 |
Correct |
3 ms |
1556 KB |
Output is correct |
15 |
Correct |
11 ms |
2588 KB |
Output is correct |
16 |
Correct |
14 ms |
2564 KB |
Output is correct |
17 |
Correct |
13 ms |
2388 KB |
Output is correct |
18 |
Correct |
8 ms |
2520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
15528 KB |
Output is correct |
2 |
Correct |
56 ms |
6820 KB |
Output is correct |
3 |
Correct |
358 ms |
23436 KB |
Output is correct |
4 |
Correct |
79 ms |
11432 KB |
Output is correct |
5 |
Correct |
232 ms |
19416 KB |
Output is correct |
6 |
Correct |
745 ms |
33604 KB |
Output is correct |
7 |
Correct |
8 ms |
16212 KB |
Output is correct |
8 |
Correct |
9 ms |
15444 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
15832 KB |
Output is correct |
12 |
Correct |
1 ms |
852 KB |
Output is correct |
13 |
Correct |
48 ms |
6720 KB |
Output is correct |
14 |
Correct |
28 ms |
4736 KB |
Output is correct |
15 |
Correct |
25 ms |
5256 KB |
Output is correct |
16 |
Correct |
25 ms |
2512 KB |
Output is correct |
17 |
Correct |
122 ms |
12296 KB |
Output is correct |
18 |
Correct |
107 ms |
12240 KB |
Output is correct |
19 |
Correct |
77 ms |
11412 KB |
Output is correct |
20 |
Correct |
74 ms |
10556 KB |
Output is correct |
21 |
Correct |
198 ms |
19692 KB |
Output is correct |
22 |
Correct |
219 ms |
19276 KB |
Output is correct |
23 |
Correct |
232 ms |
17440 KB |
Output is correct |
24 |
Correct |
193 ms |
19764 KB |
Output is correct |
25 |
Correct |
390 ms |
23416 KB |
Output is correct |
26 |
Correct |
437 ms |
21400 KB |
Output is correct |
27 |
Correct |
605 ms |
25192 KB |
Output is correct |
28 |
Correct |
726 ms |
33440 KB |
Output is correct |
29 |
Correct |
707 ms |
31872 KB |
Output is correct |
30 |
Correct |
640 ms |
30848 KB |
Output is correct |
31 |
Correct |
513 ms |
20680 KB |
Output is correct |
32 |
Correct |
495 ms |
24308 KB |
Output is correct |