#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << endl
#define all(x) x.begin(),x.end()
bool vis[4010][4010];
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n,m;cin>>n>>m;
string s[n];
for(int i=0;i<n;i++) cin>>s[i];
priority_queue<pair<int,pii>> pq;
pq.push({0,{0,0}});
int ans=0;
while(!pq.empty())
{
int x=pq.top().se.fi,y=pq.top().se.se,v=-pq.top().fi;
pq.pop();
if(vis[x][y]) continue;
ans=max(ans,v);
vis[x][y]=1;
if(x+1<n && !vis[x+1][y]) pq.push({-(v+(s[x][y]!=s[x+1][y])),{x+1,y}});
if(y+1<n && !vis[x][y+1]) pq.push({-(v+(s[x][y]!=s[x][y+1])),{x,y+1}});
}
cout<<ans+1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
2652 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
4 |
Incorrect |
17 ms |
2740 KB |
Output isn't correct |
5 |
Incorrect |
7 ms |
1624 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
1628 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
1116 KB |
Output isn't correct |
12 |
Incorrect |
8 ms |
1628 KB |
Output isn't correct |
13 |
Incorrect |
6 ms |
1628 KB |
Output isn't correct |
14 |
Incorrect |
8 ms |
1628 KB |
Output isn't correct |
15 |
Incorrect |
26 ms |
2908 KB |
Output isn't correct |
16 |
Incorrect |
25 ms |
2732 KB |
Output isn't correct |
17 |
Incorrect |
22 ms |
2680 KB |
Output isn't correct |
18 |
Incorrect |
17 ms |
2652 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
216 ms |
31760 KB |
Execution killed with signal 11 |
2 |
Incorrect |
134 ms |
10956 KB |
Output isn't correct |
3 |
Incorrect |
1243 ms |
60332 KB |
Output isn't correct |
4 |
Incorrect |
272 ms |
12076 KB |
Output isn't correct |
5 |
Incorrect |
666 ms |
71856 KB |
Output isn't correct |
6 |
Incorrect |
1297 ms |
37140 KB |
Output isn't correct |
7 |
Incorrect |
1152 ms |
16472 KB |
Output isn't correct |
8 |
Incorrect |
1066 ms |
15704 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
944 ms |
16140 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
1112 KB |
Output isn't correct |
13 |
Incorrect |
132 ms |
11368 KB |
Output isn't correct |
14 |
Incorrect |
73 ms |
6352 KB |
Output isn't correct |
15 |
Incorrect |
71 ms |
6316 KB |
Output isn't correct |
16 |
Incorrect |
12 ms |
3156 KB |
Output isn't correct |
17 |
Incorrect |
356 ms |
16840 KB |
Output isn't correct |
18 |
Incorrect |
292 ms |
14032 KB |
Output isn't correct |
19 |
Incorrect |
267 ms |
12060 KB |
Output isn't correct |
20 |
Incorrect |
232 ms |
17344 KB |
Output isn't correct |
21 |
Incorrect |
729 ms |
36392 KB |
Output isn't correct |
22 |
Incorrect |
667 ms |
73124 KB |
Output isn't correct |
23 |
Incorrect |
592 ms |
31016 KB |
Output isn't correct |
24 |
Incorrect |
646 ms |
26312 KB |
Output isn't correct |
25 |
Incorrect |
1805 ms |
83908 KB |
Output isn't correct |
26 |
Correct |
477 ms |
27736 KB |
Output is correct |
27 |
Incorrect |
880 ms |
35532 KB |
Output isn't correct |
28 |
Incorrect |
1314 ms |
37832 KB |
Output isn't correct |
29 |
Incorrect |
1267 ms |
37060 KB |
Output isn't correct |
30 |
Incorrect |
1072 ms |
37320 KB |
Output isn't correct |
31 |
Incorrect |
1185 ms |
24412 KB |
Output isn't correct |
32 |
Incorrect |
908 ms |
35532 KB |
Output isn't correct |