/// (⌐■_■): "who's nvpu, dwuy?"
/// dwuy : "revolym"
#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK ""
using namespace std;
typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;
const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 4005;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
int n, m;
string a[MX];
int d[MX][MX];
void nhap(){
cin >> n >> m;
for(int i=0; i<n; i++) cin >> a[i];
}
void solve(){
deque<pii> Q;
d[0][0] = 1;
Q.push_front({0, 0});
int ans = 0;
while(Q.size()){
int x, y;
tie(x, y) = Q.front();
Q.pop_front();
ans = max(ans, d[x][y]);
for(int i=0; i<4; i++){
int u = x + dx[i];
int v = y + dy[i];
if(u<0 || u>=n || v<0 || v>=m || d[u][v]!=0 || a[u][v]=='.') continue;
if(a[u][v] == a[x][y]){
d[u][v] = d[x][y];
Q.push_front({u, v});
}
else{
d[u][v] = d[x][y] + 1;
Q.push_back({u, v});
}
}
}
cout << ans;
}
int32_t main(){
fastIO;
//file(TASK);
nhap();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3572 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
7 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
1876 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
1620 KB |
Output is correct |
11 |
Correct |
3 ms |
1492 KB |
Output is correct |
12 |
Correct |
4 ms |
2076 KB |
Output is correct |
13 |
Correct |
2 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
10 ms |
3412 KB |
Output is correct |
16 |
Correct |
12 ms |
3628 KB |
Output is correct |
17 |
Correct |
9 ms |
3488 KB |
Output is correct |
18 |
Correct |
8 ms |
3364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15872 KB |
Output is correct |
2 |
Correct |
29 ms |
10384 KB |
Output is correct |
3 |
Correct |
171 ms |
59868 KB |
Output is correct |
4 |
Correct |
44 ms |
25676 KB |
Output is correct |
5 |
Correct |
90 ms |
42624 KB |
Output is correct |
6 |
Correct |
547 ms |
93536 KB |
Output is correct |
7 |
Correct |
11 ms |
16596 KB |
Output is correct |
8 |
Correct |
13 ms |
15956 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
18 ms |
16340 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
30 ms |
10304 KB |
Output is correct |
14 |
Correct |
25 ms |
6980 KB |
Output is correct |
15 |
Correct |
14 ms |
9336 KB |
Output is correct |
16 |
Correct |
14 ms |
4308 KB |
Output is correct |
17 |
Correct |
79 ms |
21352 KB |
Output is correct |
18 |
Correct |
66 ms |
28256 KB |
Output is correct |
19 |
Correct |
55 ms |
25640 KB |
Output is correct |
20 |
Correct |
39 ms |
19096 KB |
Output is correct |
21 |
Correct |
97 ms |
41280 KB |
Output is correct |
22 |
Correct |
92 ms |
42612 KB |
Output is correct |
23 |
Correct |
164 ms |
34920 KB |
Output is correct |
24 |
Correct |
106 ms |
38560 KB |
Output is correct |
25 |
Correct |
322 ms |
80792 KB |
Output is correct |
26 |
Correct |
558 ms |
118860 KB |
Output is correct |
27 |
Correct |
533 ms |
100496 KB |
Output is correct |
28 |
Correct |
565 ms |
93608 KB |
Output is correct |
29 |
Correct |
527 ms |
92440 KB |
Output is correct |
30 |
Correct |
539 ms |
92472 KB |
Output is correct |
31 |
Correct |
365 ms |
62024 KB |
Output is correct |
32 |
Correct |
529 ms |
89072 KB |
Output is correct |