#include<bits/stdc++.h>
#define space <<' '<<
#define endl '\n'
#define inf 1e14
#define F first
#define S second
#define PB push_back
#define PF push_front
#define md(a) ((a+mod)%mod)
#define MP(a,b) make_pair(a,b)
#define MT(a,b,c) make_tuple(a,b,c)
typedef long long ll;
using namespace std;
template<typename t> using heap=
priority_queue<t,vector<t>,greater<t>>;
const ll mx = 4005;
ll D[mx][mx];
char s[mx][mx];
bool seen[mx][mx];
set<pair<ll,pair<ll,ll>>> l;
pair<ll,ll> n[]={MP(0,1),MP(0,-1),MP(1,0),MP(-1,0)};
int main(){
std::ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll h,w;cin>>h>>w;
for(ll i=0;i<h;i++)
for(ll j=0;j<w;j++){
cin>>s[i][j];
D[i][j]=2e7;
}
ll o=0;
D[0][0]=1;
l.insert(MP(1,MP(0,0)));
while(!l.empty()){
auto d=l.begin()->S;
l.erase(l.begin());
if(seen[d.F][d.S])
continue;
seen[d.F][d.S]=1;
o=max(o,D[d.F][d.S]);
for(ll p,x,y,i=0;i<4;i++){
x=d.F+n[i].F,y=d.S+n[i].S;
if(0<=x&&x<h&&0<=y&&y<w)
if(s[x][y]!='.'){
p=s[d.F][d.S]!=s[x][y];
if(D[d.F][d.S]+p<D[x][y]){
D[x][y]=D[d.F][d.S]+p;
l.insert(MP(D[x][y],MP(x,y)));
}
}
}
}
cout<<o;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
23 ms |
8676 KB |
Output is correct |
5 |
Correct |
6 ms |
4440 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
5 ms |
3932 KB |
Output is correct |
11 |
Correct |
6 ms |
3420 KB |
Output is correct |
12 |
Correct |
14 ms |
4940 KB |
Output is correct |
13 |
Correct |
5 ms |
4444 KB |
Output is correct |
14 |
Correct |
5 ms |
4444 KB |
Output is correct |
15 |
Correct |
31 ms |
8792 KB |
Output is correct |
16 |
Correct |
38 ms |
8792 KB |
Output is correct |
17 |
Correct |
19 ms |
8280 KB |
Output is correct |
18 |
Correct |
23 ms |
8536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
46172 KB |
Output is correct |
2 |
Correct |
112 ms |
29012 KB |
Output is correct |
3 |
Correct |
460 ms |
172776 KB |
Output is correct |
4 |
Correct |
142 ms |
55636 KB |
Output is correct |
5 |
Correct |
253 ms |
115028 KB |
Output is correct |
6 |
Execution timed out |
2081 ms |
249560 KB |
Time limit exceeded |
7 |
Correct |
19 ms |
48220 KB |
Output is correct |
8 |
Correct |
18 ms |
46168 KB |
Output is correct |
9 |
Correct |
4 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
22 ms |
47448 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
107 ms |
28952 KB |
Output is correct |
14 |
Correct |
57 ms |
19288 KB |
Output is correct |
15 |
Correct |
30 ms |
21080 KB |
Output is correct |
16 |
Correct |
50 ms |
10844 KB |
Output is correct |
17 |
Correct |
272 ms |
60032 KB |
Output is correct |
18 |
Correct |
118 ms |
59184 KB |
Output is correct |
19 |
Correct |
144 ms |
55640 KB |
Output is correct |
20 |
Correct |
128 ms |
51536 KB |
Output is correct |
21 |
Correct |
281 ms |
119120 KB |
Output is correct |
22 |
Correct |
311 ms |
115168 KB |
Output is correct |
23 |
Correct |
519 ms |
98312 KB |
Output is correct |
24 |
Correct |
218 ms |
117332 KB |
Output is correct |
25 |
Correct |
616 ms |
172628 KB |
Output is correct |
26 |
Correct |
1518 ms |
149604 KB |
Output is correct |
27 |
Correct |
1959 ms |
185248 KB |
Output is correct |
28 |
Execution timed out |
2051 ms |
249480 KB |
Time limit exceeded |
29 |
Execution timed out |
2079 ms |
237832 KB |
Time limit exceeded |
30 |
Execution timed out |
2067 ms |
226644 KB |
Time limit exceeded |
31 |
Correct |
1618 ms |
131724 KB |
Output is correct |
32 |
Correct |
1566 ms |
179024 KB |
Output is correct |