#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 4e3 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;
char c;
ll n,m,a[N][N],cnt,ans,was[N][N];
ll dx[4] = {0,0,1,-1};
ll dy[4] = {1,-1,0,0};
bool chk(ll x,ll y){
return x <= n&&y <= m&&x > 0&&y > 0;
}
queue<LL> q,differ;
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n>>m;
for (ll i = 1;i <= n;i++)
for (ll j = 1;j <= m;j++){
cin>>c; cnt += (c != '.');
if (c == '.') a[i][j] = 2;
if (c == 'F') a[i][j] = 1;
}
ll now = a[1][1],cur = 0; was[1][1] = 1; q.push({1,1});
while(cur < cnt){
ans++;
while(!q.empty()){
LL t = q.front(); q.pop(); cur++;
for (ll i = 0;i < 4;i++){
ll x = t.fs + dx[i],y = t.sc + dy[i];
if (!chk(x,y) || was[x][y]) continue;
was[x][y] = 1;
if (a[x][y] == now) q.push({x,y});
else if (a[x][y] == 1 - now) differ.push({x,y});
}
}
//cout<<cur; return 0;
now ^= 1;
while(!differ.empty()) q.push(differ.front()),differ.pop();
}
cout<<ans;
}
Compilation message
tracks.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization O2
|
tracks.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
tracks.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
3 | #pragma target ("avx2")
|
tracks.cpp: In function 'int main()':
tracks.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
6380 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
12 ms |
5796 KB |
Output is correct |
5 |
Correct |
5 ms |
3276 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
844 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
4 ms |
2764 KB |
Output is correct |
11 |
Correct |
4 ms |
2256 KB |
Output is correct |
12 |
Correct |
8 ms |
3428 KB |
Output is correct |
13 |
Correct |
6 ms |
3276 KB |
Output is correct |
14 |
Correct |
5 ms |
3328 KB |
Output is correct |
15 |
Correct |
19 ms |
6368 KB |
Output is correct |
16 |
Correct |
26 ms |
6348 KB |
Output is correct |
17 |
Correct |
16 ms |
6216 KB |
Output is correct |
18 |
Correct |
12 ms |
5720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31436 KB |
Output is correct |
2 |
Correct |
89 ms |
22604 KB |
Output is correct |
3 |
Correct |
550 ms |
122080 KB |
Output is correct |
4 |
Correct |
151 ms |
46916 KB |
Output is correct |
5 |
Correct |
347 ms |
99648 KB |
Output is correct |
6 |
Correct |
1748 ms |
141456 KB |
Output is correct |
7 |
Correct |
23 ms |
32788 KB |
Output is correct |
8 |
Correct |
18 ms |
31472 KB |
Output is correct |
9 |
Correct |
3 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
19 ms |
32208 KB |
Output is correct |
12 |
Correct |
2 ms |
1744 KB |
Output is correct |
13 |
Correct |
93 ms |
22608 KB |
Output is correct |
14 |
Correct |
51 ms |
14780 KB |
Output is correct |
15 |
Correct |
48 ms |
17064 KB |
Output is correct |
16 |
Correct |
37 ms |
8808 KB |
Output is correct |
17 |
Correct |
252 ms |
46912 KB |
Output is correct |
18 |
Correct |
189 ms |
50372 KB |
Output is correct |
19 |
Correct |
154 ms |
46544 KB |
Output is correct |
20 |
Correct |
121 ms |
40952 KB |
Output is correct |
21 |
Correct |
316 ms |
92632 KB |
Output is correct |
22 |
Correct |
317 ms |
99316 KB |
Output is correct |
23 |
Correct |
492 ms |
77416 KB |
Output is correct |
24 |
Correct |
349 ms |
97880 KB |
Output is correct |
25 |
Correct |
874 ms |
131032 KB |
Output is correct |
26 |
Correct |
841 ms |
60212 KB |
Output is correct |
27 |
Correct |
1285 ms |
132816 KB |
Output is correct |
28 |
Correct |
1643 ms |
141416 KB |
Output is correct |
29 |
Correct |
1557 ms |
139744 KB |
Output is correct |
30 |
Correct |
1386 ms |
131996 KB |
Output is correct |
31 |
Correct |
1131 ms |
106048 KB |
Output is correct |
32 |
Correct |
1169 ms |
131828 KB |
Output is correct |