# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
725488 |
2023-04-17T14:11:24 Z |
kerem |
Zoo (COCI19_zoo) |
C++14 |
|
108 ms |
10240 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fir first
#define sec second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,m,vis[1005][1005];
char a[1005][1005];
queue<pair<int,int>> kalan;
void bfs(char c,char c1){
queue<pair<int,int>> q;
while(!kalan.empty()){
q.push({kalan.front().fir,kalan.front().sec});
kalan.pop();
}
while(!q.empty()){
int x=q.front().fir;
int y=q.front().sec;
q.pop();
if(vis[x][y]==1) continue;
vis[x][y]=1;
if(a[x+1][y]==c and vis[x+1][y]!=1)
q.push({x+1,y});
if(a[x-1][y]==c and vis[x-1][y]!=1)
q.push({x-1,y});
if(a[x][y+1]==c and vis[x][y+1]!=1)
q.push({x,y+1});
if(a[x][y-1]==c and vis[x][y-1]!=1)
q.push({x,y-1});
if(a[x+1][y]==c1 and vis[x+1][y]!=1)
kalan.push({x+1,y});
if(a[x-1][y]==c1 and vis[x-1][y]!=1)
kalan.push({x-1,y});
if(a[x][y+1]==c1 and vis[x][y+1]!=1)
kalan.push({x,y+1});
if(a[x][y-1]==c1 and vis[x][y-1]!=1)
kalan.push({x,y-1});
}
return;
}
int32_t main(){
int ans=0;
memset(vis,0,sizeof(vis));
cin >> n >> m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin >> a[i][j];
kalan.push({1,1});
char c=a[1][1],c1;
if(c=='B') c1='T';
else c1='B';
while(!kalan.empty()){
ans++;
bfs(c,c1);
char temp=c;
c=c1;
c1=temp;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
4 ms |
8276 KB |
Output is correct |
6 |
Correct |
5 ms |
8276 KB |
Output is correct |
7 |
Correct |
5 ms |
8276 KB |
Output is correct |
8 |
Correct |
6 ms |
8288 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
5 ms |
8276 KB |
Output is correct |
11 |
Correct |
5 ms |
8316 KB |
Output is correct |
12 |
Correct |
6 ms |
8276 KB |
Output is correct |
13 |
Correct |
4 ms |
8276 KB |
Output is correct |
14 |
Correct |
5 ms |
8276 KB |
Output is correct |
15 |
Correct |
4 ms |
8276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
3 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8148 KB |
Output is correct |
5 |
Correct |
4 ms |
8276 KB |
Output is correct |
6 |
Correct |
5 ms |
8276 KB |
Output is correct |
7 |
Correct |
5 ms |
8276 KB |
Output is correct |
8 |
Correct |
6 ms |
8288 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
5 ms |
8276 KB |
Output is correct |
11 |
Correct |
5 ms |
8316 KB |
Output is correct |
12 |
Correct |
6 ms |
8276 KB |
Output is correct |
13 |
Correct |
4 ms |
8276 KB |
Output is correct |
14 |
Correct |
5 ms |
8276 KB |
Output is correct |
15 |
Correct |
4 ms |
8276 KB |
Output is correct |
16 |
Correct |
64 ms |
9408 KB |
Output is correct |
17 |
Correct |
62 ms |
9396 KB |
Output is correct |
18 |
Correct |
64 ms |
9264 KB |
Output is correct |
19 |
Correct |
71 ms |
9336 KB |
Output is correct |
20 |
Correct |
63 ms |
9312 KB |
Output is correct |
21 |
Correct |
108 ms |
9164 KB |
Output is correct |
22 |
Correct |
97 ms |
10008 KB |
Output is correct |
23 |
Correct |
99 ms |
10136 KB |
Output is correct |
24 |
Correct |
104 ms |
10204 KB |
Output is correct |
25 |
Correct |
103 ms |
10188 KB |
Output is correct |
26 |
Correct |
104 ms |
10240 KB |
Output is correct |
27 |
Correct |
97 ms |
10088 KB |
Output is correct |
28 |
Correct |
95 ms |
10112 KB |
Output is correct |
29 |
Correct |
104 ms |
10188 KB |
Output is correct |
30 |
Correct |
103 ms |
10164 KB |
Output is correct |