# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
708517 |
2023-03-12T02:12:00 Z |
pcc |
Zoo (COCI19_zoo) |
C++14 |
|
29 ms |
2516 KB |
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second
const int mxn = 1010;
string arr[mxn];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
for(int i = 0;i<n;i++)cin>>arr[i];
string col = "TB";
int now = 0;
queue<pii> q[2];
if(col[now] != arr[0][0])now^=1;
q[now].push({0,0});
arr[0][0] = '*';
int ans = 0;
pii dir[] = {{0,1},{0,-1},{1,0},{-1,0}};
while(!q[0].empty()||!q[1].empty()){
ans++;
// for(int i = 0;i<n;i++){
// for(int j = 0;j<m;j++)cout<<arr[i][j];cout<<endl;
// }
// cout<<ans<<' '<<q[0].size()<<' '<<q[1].size()<<endl;
while(!q[now].empty()){
auto pos = q[now].front();
q[now].pop();
for(auto &i:dir){
pii nxt = {pos.fs+i.fs,pos.sc+i.sc};
if(nxt.fs<0||nxt.fs>=n||nxt.sc<0||nxt.sc>=m||arr[nxt.fs][nxt.sc] == '*')continue;
q[(col[now] == arr[nxt.fs][nxt.sc]?now:now^1)].push(nxt);
arr[nxt.fs][nxt.sc] = '*';
}
}
now^=1;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
360 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
360 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
2272 KB |
Output is correct |
17 |
Correct |
5 ms |
2276 KB |
Output is correct |
18 |
Correct |
5 ms |
2388 KB |
Output is correct |
19 |
Correct |
8 ms |
2516 KB |
Output is correct |
20 |
Correct |
5 ms |
2364 KB |
Output is correct |
21 |
Correct |
27 ms |
2228 KB |
Output is correct |
22 |
Correct |
27 ms |
2236 KB |
Output is correct |
23 |
Correct |
29 ms |
2244 KB |
Output is correct |
24 |
Correct |
29 ms |
2260 KB |
Output is correct |
25 |
Correct |
29 ms |
2216 KB |
Output is correct |
26 |
Correct |
27 ms |
2268 KB |
Output is correct |
27 |
Correct |
28 ms |
2132 KB |
Output is correct |
28 |
Correct |
27 ms |
2208 KB |
Output is correct |
29 |
Correct |
27 ms |
2312 KB |
Output is correct |
30 |
Correct |
27 ms |
2248 KB |
Output is correct |