#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
char g[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>g[i][j];
}
}
vector<pair<pi,bool> > adj[n][m];
int vis[n][m];
memset(vis,-1,sizeof vis);
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
for(int d=0;d<4;d++)
{
int ni=i+dx[d],nj=j+dy[d];
if(ni<n && ni>=0 && nj<m && nj>=0 && g[i][j]!='.' && g[ni][nj]!='.'){
adj[i][j].pb({{ni,nj},!(g[i][j]==g[ni][nj])});
}
}
}
}
deque<pi> dq;
dq.pb({0,0});vis[0][0]=0;
int ans=0;
while(!dq.empty()){
int i=dq.front().F,j=dq.front().S;
dq.pop_back();
for(auto p:adj[i][j])
{
int ni=p.F.F,nj=p.F.S,w=p.S;
if(vis[ni][nj]!=-1)continue;
vis[ni][nj]=w+vis[i][j];
ans=max(ans,vis[ni][nj]);
if(w)dq.pb({ni,nj});
else dq.push_front({ni,nj});
}
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
22096 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
4 |
Incorrect |
21 ms |
14420 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
3932 KB |
Output isn't correct |
12 |
Incorrect |
11 ms |
8044 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
15 |
Incorrect |
27 ms |
18516 KB |
Output isn't correct |
16 |
Incorrect |
33 ms |
22028 KB |
Output isn't correct |
17 |
Incorrect |
19 ms |
12884 KB |
Output isn't correct |
18 |
Incorrect |
21 ms |
14524 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
2144 KB |
Output isn't correct |
2 |
Incorrect |
115 ms |
82484 KB |
Output isn't correct |
3 |
Incorrect |
855 ms |
656592 KB |
Output isn't correct |
4 |
Incorrect |
188 ms |
133200 KB |
Output isn't correct |
5 |
Incorrect |
617 ms |
405380 KB |
Output isn't correct |
6 |
Runtime error |
1410 ms |
1048576 KB |
Execution killed with signal 9 |
7 |
Incorrect |
3 ms |
2140 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
2348 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
1628 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
1884 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
1372 KB |
Output isn't correct |
13 |
Incorrect |
113 ms |
82516 KB |
Output isn't correct |
14 |
Incorrect |
66 ms |
47956 KB |
Output isn't correct |
15 |
Incorrect |
59 ms |
38572 KB |
Output isn't correct |
16 |
Incorrect |
69 ms |
39760 KB |
Output isn't correct |
17 |
Incorrect |
292 ms |
209972 KB |
Output isn't correct |
18 |
Incorrect |
242 ms |
152548 KB |
Output isn't correct |
19 |
Incorrect |
189 ms |
133356 KB |
Output isn't correct |
20 |
Incorrect |
193 ms |
145432 KB |
Output isn't correct |
21 |
Incorrect |
516 ms |
384952 KB |
Output isn't correct |
22 |
Incorrect |
618 ms |
405220 KB |
Output isn't correct |
23 |
Incorrect |
558 ms |
408340 KB |
Output isn't correct |
24 |
Incorrect |
506 ms |
361112 KB |
Output isn't correct |
25 |
Incorrect |
897 ms |
612432 KB |
Output isn't correct |
26 |
Runtime error |
1409 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Runtime error |
1383 ms |
1048576 KB |
Execution killed with signal 9 |
28 |
Runtime error |
1333 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Runtime error |
1312 ms |
1048576 KB |
Execution killed with signal 9 |
30 |
Runtime error |
1337 ms |
1048576 KB |
Execution killed with signal 9 |
31 |
Incorrect |
1347 ms |
939768 KB |
Output isn't correct |
32 |
Runtime error |
1360 ms |
1048576 KB |
Execution killed with signal 9 |