#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=3333;
char a[N][N];
bool vis[N][N];
int xx[4]={1,-1,0,0};
int yy[4]={0,0,1,-1};
pair<int,int>par[N][N];
int lvl[N][N];
bool lvlvis[N*N];
signed main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)cin>>a[i][j];
}
queue<pair<int,int>>q,hq;
q.push({n,m});
int p=1;
while(!(q.empty() and hq.empty())){
int y,x;
if(!q.empty()){
y=q.front().ff,x=q.front().ss;
q.pop();
if(vis[y][x])continue;
}
else{
y=hq.front().ff,x=hq.front().ss;
hq.pop();
if(vis[y][x]==0){
int py=par[y][x].ff,px=par[y][x].ss;
if(lvlvis[lvl[py][px]]==0)p++;
lvlvis[lvl[py][px]]=1;
}
}
vis[y][x]=1;
lvl[y][x]=p;
for(int i=0;i<4;i++){
if(vis[y+yy[i]][x+xx[i]]==0){
if(a[y+yy[i]][x+xx[i]]==a[y][x]){
q.push({y+yy[i],x+xx[i]});
}
else if(a[y+yy[i]][x+xx[i]]=='F' or a[y+yy[i]][x+xx[i]]=='R'){
par[y+yy[i]][x+xx[i]]={y,x};
hq.push({y+yy[i],x+xx[i]});
}
}
}
}
cout<<p;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
13392 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
17 ms |
11580 KB |
Output is correct |
5 |
Correct |
6 ms |
5976 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1372 KB |
Output is correct |
9 |
Correct |
1 ms |
1884 KB |
Output is correct |
10 |
Correct |
5 ms |
4700 KB |
Output is correct |
11 |
Correct |
4 ms |
4188 KB |
Output is correct |
12 |
Correct |
11 ms |
6748 KB |
Output is correct |
13 |
Correct |
6 ms |
5980 KB |
Output is correct |
14 |
Correct |
5 ms |
5980 KB |
Output is correct |
15 |
Correct |
24 ms |
12072 KB |
Output is correct |
16 |
Correct |
26 ms |
13404 KB |
Output is correct |
17 |
Correct |
18 ms |
12516 KB |
Output is correct |
18 |
Correct |
19 ms |
11608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
22364 KB |
Execution killed with signal 11 |
2 |
Correct |
94 ms |
35412 KB |
Output is correct |
3 |
Runtime error |
380 ms |
22372 KB |
Execution killed with signal 11 |
4 |
Correct |
192 ms |
108532 KB |
Output is correct |
5 |
Correct |
383 ms |
153940 KB |
Output is correct |
6 |
Runtime error |
362 ms |
22468 KB |
Execution killed with signal 11 |
7 |
Runtime error |
16 ms |
22360 KB |
Execution killed with signal 11 |
8 |
Runtime error |
24 ms |
22404 KB |
Execution killed with signal 11 |
9 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
11 |
Runtime error |
16 ms |
22496 KB |
Execution killed with signal 11 |
12 |
Correct |
2 ms |
3160 KB |
Output is correct |
13 |
Correct |
92 ms |
35412 KB |
Output is correct |
14 |
Correct |
60 ms |
23380 KB |
Output is correct |
15 |
Correct |
65 ms |
38120 KB |
Output is correct |
16 |
Correct |
41 ms |
14928 KB |
Output is correct |
17 |
Correct |
252 ms |
71996 KB |
Output is correct |
18 |
Correct |
213 ms |
123220 KB |
Output is correct |
19 |
Correct |
184 ms |
108384 KB |
Output is correct |
20 |
Correct |
150 ms |
52564 KB |
Output is correct |
21 |
Correct |
421 ms |
110356 KB |
Output is correct |
22 |
Correct |
439 ms |
153804 KB |
Output is correct |
23 |
Correct |
469 ms |
117336 KB |
Output is correct |
24 |
Correct |
377 ms |
116084 KB |
Output is correct |
25 |
Runtime error |
378 ms |
22352 KB |
Execution killed with signal 11 |
26 |
Runtime error |
366 ms |
22412 KB |
Execution killed with signal 11 |
27 |
Runtime error |
371 ms |
22352 KB |
Execution killed with signal 11 |
28 |
Runtime error |
366 ms |
22556 KB |
Execution killed with signal 11 |
29 |
Runtime error |
365 ms |
22356 KB |
Execution killed with signal 11 |
30 |
Runtime error |
389 ms |
22448 KB |
Execution killed with signal 11 |
31 |
Correct |
1006 ms |
273748 KB |
Output is correct |
32 |
Runtime error |
385 ms |
22360 KB |
Execution killed with signal 11 |