#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const int inf = 1e9 + 10000;
const int mod = 1e9+7;
const int maxn = 1e4 + 12;
char a[maxn][maxn];
bool was[maxn][maxn];
queue<pair<pii, int>> q;
void go(int x, int y, int s){
q.push({{x, y}, s});
was[x][y] = 1;
if(!was[x - 1][y] && a[x][y] == a[x - 1][y])go(x - 1, y, s);
if(!was[x + 1][y] && a[x][y] == a[x + 1][y])go(x + 1, y, s);
if(!was[x][y - 1] && a[x][y] == a[x][y - 1])go(x, y - 1, s);
if(!was[x][y + 1] && a[x][y] == a[x][y + 1])go(x, y + 1, s);
}
void solve() {
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++){
was[i][0] = was[i][m + 1] = 1;
for(int j = 1; j <= m; j++){
cin >> a[i][j];
if(a[i][j] == '*')was[i][j] = 1;
}
}
for(int i = 1; i <= m; i++)was[0][i] = was[n + 1][i] = 1;
int ans = 0;
go(n, m, 1);
while(!q.empty()){
pair<pii, int> nw = q.front();
q.pop();
int x = nw.ff.ff, y = nw.ff.ss, s = nw.ss;
ans = max(ans, s);
if(!was[x - 1][y] && a[x][y] != a[x - 1][y])go(x - 1, y, s + 1);
if(!was[x + 1][y] && a[x][y] != a[x + 1][y])go(x + 1, y, s + 1);
if(!was[x][y - 1] && a[x][y] != a[x][y - 1])go(x, y - 1, s + 1);
if(!was[x][y + 1] && a[x][y] != a[x][y + 1])go(x, y + 1, s + 1);
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
15452 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Correct |
9 ms |
16988 KB |
Output is correct |
5 |
Incorrect |
5 ms |
12124 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
8 |
Correct |
1 ms |
4952 KB |
Output is correct |
9 |
Incorrect |
2 ms |
7000 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
9308 KB |
Output isn't correct |
11 |
Correct |
3 ms |
7516 KB |
Output is correct |
12 |
Incorrect |
5 ms |
10840 KB |
Output isn't correct |
13 |
Incorrect |
6 ms |
12124 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
12124 KB |
Output isn't correct |
15 |
Incorrect |
12 ms |
16428 KB |
Output isn't correct |
16 |
Incorrect |
11 ms |
15452 KB |
Output isn't correct |
17 |
Incorrect |
12 ms |
14172 KB |
Output isn't correct |
18 |
Correct |
8 ms |
16988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
79196 KB |
Output isn't correct |
2 |
Incorrect |
60 ms |
40900 KB |
Output isn't correct |
3 |
Incorrect |
588 ms |
255648 KB |
Output isn't correct |
4 |
Incorrect |
130 ms |
65616 KB |
Output isn't correct |
5 |
Incorrect |
216 ms |
151532 KB |
Output isn't correct |
6 |
Correct |
652 ms |
237420 KB |
Output is correct |
7 |
Incorrect |
15 ms |
83292 KB |
Output isn't correct |
8 |
Incorrect |
15 ms |
79196 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
3932 KB |
Output isn't correct |
11 |
Incorrect |
15 ms |
82264 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
6744 KB |
Output isn't correct |
13 |
Incorrect |
55 ms |
40928 KB |
Output isn't correct |
14 |
Incorrect |
33 ms |
31468 KB |
Output isn't correct |
15 |
Incorrect |
61 ms |
55372 KB |
Output isn't correct |
16 |
Incorrect |
24 ms |
16472 KB |
Output isn't correct |
17 |
Incorrect |
143 ms |
78420 KB |
Output isn't correct |
18 |
Incorrect |
275 ms |
178056 KB |
Output isn't correct |
19 |
Incorrect |
141 ms |
65716 KB |
Output isn't correct |
20 |
Incorrect |
127 ms |
78676 KB |
Output isn't correct |
21 |
Incorrect |
350 ms |
164440 KB |
Output isn't correct |
22 |
Incorrect |
217 ms |
151296 KB |
Output isn't correct |
23 |
Incorrect |
273 ms |
115756 KB |
Output isn't correct |
24 |
Incorrect |
272 ms |
140224 KB |
Output isn't correct |
25 |
Incorrect |
1028 ms |
530492 KB |
Output isn't correct |
26 |
Runtime error |
798 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Correct |
859 ms |
551236 KB |
Output is correct |
28 |
Correct |
677 ms |
241584 KB |
Output is correct |
29 |
Correct |
669 ms |
229788 KB |
Output is correct |
30 |
Correct |
716 ms |
334216 KB |
Output is correct |
31 |
Incorrect |
362 ms |
76256 KB |
Output isn't correct |
32 |
Incorrect |
992 ms |
648240 KB |
Output isn't correct |