#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
using namespace std;
typedef long long ll;
int add(int a, int b)
{
ll x = a+b;
if(x >= mod)
x -= mod;
if(x < 0)
x += mod;
return x;
}
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
ll pw(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
int n, m;
char c[4002][4002];
bool blocked[4002][4002];
int ans = 0;
int ox[] = {-1, 0, 1, 0};
int oy[] = {0, 1, 0, -1};
bool verif(int L, int C)
{
return (L >= 1 && L <= n && C >= 1 && C <= m);
}
void lee(int L, int C)
{
char init = c[L][C];
c[L][C] = 'F';
deque<pair<int, int> >d, d2;
d.pb({L, C});
while(!d.empty() || !d2.empty())
{
++ans;
while(!d.empty())
{
pair<int, int> poz = d[0];
d.pop_front();
for(int i = 0; i <= 3; ++i)
{
int X = poz.fi + ox[i];
int Y = poz.se + oy[i];
if(!verif(X, Y))
continue;
if(c[X][Y] == 'F' || c[X][Y] == '.')
continue;
if(blocked[X][Y])
continue;
if(c[X][Y] == init)
{
d.push_back({X, Y});
blocked[X][Y] = 1;
}
else
{
d2.push_back({X, Y});
blocked[X][Y] = 1;
}
}
}
if(init == 'B')
init = 'T';
else
init = 'B';
swap(d, d2);
for(int i = 0; i < d.size(); ++i)
{
pair<int, int> poz = d[0];
c[poz.fi][poz.se] = 'F';
blocked[poz.fi][poz.se] = 0;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; ++i)
cin >> (c[i] + 1);
lee(n, m);
cout << ans;
return 0;
}
Compilation message
tracks.cpp: In function 'void lee(int, int)':
tracks.cpp:91:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < d.size(); ++i)
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
1528 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
632 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
1144 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
1400 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
1528 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
1528 KB |
Output isn't correct |
15 |
Incorrect |
4 ms |
2576 KB |
Output isn't correct |
16 |
Incorrect |
4 ms |
2552 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
18 |
Incorrect |
4 ms |
2424 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
15372 KB |
Output isn't correct |
2 |
Incorrect |
13 ms |
11000 KB |
Output isn't correct |
3 |
Incorrect |
35 ms |
28296 KB |
Output isn't correct |
4 |
Incorrect |
13 ms |
9996 KB |
Output isn't correct |
5 |
Incorrect |
23 ms |
18424 KB |
Output isn't correct |
6 |
Incorrect |
160 ms |
43972 KB |
Output isn't correct |
7 |
Incorrect |
31 ms |
31736 KB |
Output isn't correct |
8 |
Incorrect |
13 ms |
15352 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Incorrect |
31 ms |
31096 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
888 KB |
Output isn't correct |
13 |
Incorrect |
14 ms |
11000 KB |
Output isn't correct |
14 |
Incorrect |
6 ms |
4604 KB |
Output isn't correct |
15 |
Incorrect |
11 ms |
8952 KB |
Output isn't correct |
16 |
Incorrect |
6 ms |
4088 KB |
Output isn't correct |
17 |
Incorrect |
23 ms |
18680 KB |
Output isn't correct |
18 |
Incorrect |
22 ms |
18552 KB |
Output isn't correct |
19 |
Incorrect |
12 ms |
9976 KB |
Output isn't correct |
20 |
Incorrect |
20 ms |
15996 KB |
Output isn't correct |
21 |
Incorrect |
38 ms |
31352 KB |
Output isn't correct |
22 |
Incorrect |
22 ms |
18424 KB |
Output isn't correct |
23 |
Incorrect |
19 ms |
15224 KB |
Output isn't correct |
24 |
Incorrect |
37 ms |
31352 KB |
Output isn't correct |
25 |
Incorrect |
35 ms |
28280 KB |
Output isn't correct |
26 |
Correct |
516 ms |
37044 KB |
Output is correct |
27 |
Incorrect |
35 ms |
28408 KB |
Output isn't correct |
28 |
Incorrect |
158 ms |
44040 KB |
Output isn't correct |
29 |
Incorrect |
173 ms |
44060 KB |
Output isn't correct |
30 |
Incorrect |
34 ms |
27768 KB |
Output isn't correct |
31 |
Incorrect |
42 ms |
33016 KB |
Output isn't correct |
32 |
Incorrect |
55 ms |
44120 KB |
Output isn't correct |