#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>
const int N=4010;
vector<pair<pi,int> >adj[N][N];
int n,m,vis[N][N],ans;
char g[N][N];
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
bool good (int i,int j)
{
return (i>-1 && j>-1 && i<n && j<m);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>g[i][j];
memset(vis,-1,sizeof vis);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(good(i,j))
for(int d=0;d<4;d++)
{
int ni=i+dx[d],nj=j+dy[d];
if(good(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;
while(!dq.empty()){
int i=dq.front().F,j=dq.front().S;
dq.pop_front();
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 |
132 ms |
459604 KB |
Output isn't correct |
2 |
Incorrect |
85 ms |
442196 KB |
Output isn't correct |
3 |
Incorrect |
86 ms |
444500 KB |
Output isn't correct |
4 |
Incorrect |
117 ms |
454228 KB |
Output isn't correct |
5 |
Incorrect |
98 ms |
449600 KB |
Output isn't correct |
6 |
Incorrect |
85 ms |
442056 KB |
Output isn't correct |
7 |
Incorrect |
87 ms |
444412 KB |
Output isn't correct |
8 |
Incorrect |
86 ms |
444616 KB |
Output isn't correct |
9 |
Incorrect |
91 ms |
445284 KB |
Output isn't correct |
10 |
Incorrect |
95 ms |
448488 KB |
Output isn't correct |
11 |
Incorrect |
92 ms |
446804 KB |
Output isn't correct |
12 |
Incorrect |
99 ms |
449876 KB |
Output isn't correct |
13 |
Incorrect |
99 ms |
449876 KB |
Output isn't correct |
14 |
Incorrect |
98 ms |
449616 KB |
Output isn't correct |
15 |
Incorrect |
127 ms |
460368 KB |
Output isn't correct |
16 |
Incorrect |
126 ms |
459692 KB |
Output isn't correct |
17 |
Incorrect |
126 ms |
459600 KB |
Output isn't correct |
18 |
Incorrect |
112 ms |
454224 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
96 ms |
459796 KB |
Output isn't correct |
2 |
Incorrect |
339 ms |
550876 KB |
Output isn't correct |
3 |
Runtime error |
1221 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Incorrect |
806 ms |
689748 KB |
Output isn't correct |
5 |
Runtime error |
1168 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Runtime error |
1247 ms |
1048576 KB |
Execution killed with signal 9 |
7 |
Incorrect |
95 ms |
459344 KB |
Output isn't correct |
8 |
Incorrect |
95 ms |
459824 KB |
Output isn't correct |
9 |
Incorrect |
93 ms |
446040 KB |
Output isn't correct |
10 |
Incorrect |
89 ms |
444240 KB |
Output isn't correct |
11 |
Incorrect |
95 ms |
459604 KB |
Output isn't correct |
12 |
Incorrect |
91 ms |
445776 KB |
Output isn't correct |
13 |
Incorrect |
340 ms |
551056 KB |
Output isn't correct |
14 |
Incorrect |
229 ms |
505756 KB |
Output isn't correct |
15 |
Incorrect |
339 ms |
512428 KB |
Output isn't correct |
16 |
Incorrect |
190 ms |
486624 KB |
Output isn't correct |
17 |
Incorrect |
722 ms |
717760 KB |
Output isn't correct |
18 |
Incorrect |
1119 ms |
714096 KB |
Output isn't correct |
19 |
Incorrect |
820 ms |
690004 KB |
Output isn't correct |
20 |
Incorrect |
644 ms |
675808 KB |
Output isn't correct |
21 |
Runtime error |
1272 ms |
1048576 KB |
Execution killed with signal 9 |
22 |
Runtime error |
1225 ms |
1048576 KB |
Execution killed with signal 9 |
23 |
Incorrect |
1289 ms |
963080 KB |
Output isn't correct |
24 |
Runtime error |
1197 ms |
1048576 KB |
Execution killed with signal 9 |
25 |
Runtime error |
1233 ms |
1048576 KB |
Execution killed with signal 9 |
26 |
Runtime error |
1211 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Runtime error |
1242 ms |
1048576 KB |
Execution killed with signal 9 |
28 |
Runtime error |
1230 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Runtime error |
1251 ms |
1048576 KB |
Execution killed with signal 9 |
30 |
Runtime error |
1233 ms |
1048576 KB |
Execution killed with signal 9 |
31 |
Runtime error |
1188 ms |
1048576 KB |
Execution killed with signal 9 |
32 |
Runtime error |
1245 ms |
1048576 KB |
Execution killed with signal 9 |