# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
456372 |
2021-08-06T14:34:49 Z |
Jasiekstrz |
Zoo (COCI19_zoo) |
C++17 |
|
71 ms |
7116 KB |
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e3;
vector<pair<int,int>> moves={{-1,0},{1,0},{0,-1},{0,1}};
char t[N+10][N+10];
int d[N+10][N+10];
queue<pair<int,pair<int,int>>> qq[2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>t[i][j];
d[i][j]=N*N+10;
if(t[i][j]=='*')
d[i][j]=-1;
}
}
qq[0].push({0,{1,1}});
while(true)
{
int dx;
pair<int,int> x;
if(!qq[0].empty())
{
dx=qq[0].front().fi;
x=qq[0].front().se;
qq[0].pop();
}
else if(!qq[1].empty())
{
dx=qq[1].front().fi;
x=qq[1].front().se;
qq[1].pop();
}
else
break;
if(d[x.fi][x.se]<=dx)
continue;
d[x.fi][x.se]=dx;
for(auto v:moves)
{
v.fi+=x.fi;
v.se+=x.se;
if(v.fi<1 || n<v.fi || v.se<1 || m<v.se)
continue;
if(t[x.fi][x.se]!=t[v.fi][v.se])
qq[1].emplace(dx+1,v);
else
qq[0].emplace(dx,v);
}
}
int mx=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
mx=max(mx,d[i][j]+1);
}
cout<<mx<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
844 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
844 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
2 ms |
708 KB |
Output is correct |
14 |
Correct |
1 ms |
844 KB |
Output is correct |
15 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
844 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
844 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
2 ms |
708 KB |
Output is correct |
14 |
Correct |
1 ms |
844 KB |
Output is correct |
15 |
Correct |
1 ms |
716 KB |
Output is correct |
16 |
Correct |
26 ms |
6916 KB |
Output is correct |
17 |
Correct |
26 ms |
6856 KB |
Output is correct |
18 |
Correct |
26 ms |
6884 KB |
Output is correct |
19 |
Correct |
29 ms |
7116 KB |
Output is correct |
20 |
Correct |
26 ms |
6872 KB |
Output is correct |
21 |
Correct |
62 ms |
6076 KB |
Output is correct |
22 |
Correct |
62 ms |
6056 KB |
Output is correct |
23 |
Correct |
64 ms |
6148 KB |
Output is correct |
24 |
Correct |
67 ms |
6340 KB |
Output is correct |
25 |
Correct |
64 ms |
6308 KB |
Output is correct |
26 |
Correct |
68 ms |
6168 KB |
Output is correct |
27 |
Correct |
64 ms |
6024 KB |
Output is correct |
28 |
Correct |
64 ms |
6084 KB |
Output is correct |
29 |
Correct |
71 ms |
6336 KB |
Output is correct |
30 |
Correct |
65 ms |
6112 KB |
Output is correct |