#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define ld double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);
using namespace std;
const int nax = 1010;
int n, m;
char s[nax][nax];
int t[nax][nax];
bool odw[nax][nax];
vector <pair<int, int>> special, all;
bool in(int r, int c) {
return 1 <= r && r <= n && 1 <= c && c <= m;
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int znak;
void dfs(int r, int c) {
odw[r][c] = 1;
all.pb(mp(r, c));
for (int g = 0; g < 4; ++g) {
int nr = r + dx[g];
int nc = c + dy[g];
if (!in(nr, nc) || t[nr][nc] != znak || odw[nr][nc]) continue;
dfs(nr, nc);
}
}
int main() {
scanf ("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf ("%s", s[i] + 1);
for (int j = 1; j <= m; ++j) {
if (s[i][j] == '*') t[i][j] = 2;
else t[i][j] = (s[i][j] == 'T');
}
}
special.pb(mp(1, 1));
int ans = 0;
while (true) {
if (special.empty()) break;
ans++;
znak = t[special[0].fi][special[0].se];
all.clear();
for (auto it : special)
if (!odw[it.fi][it.se])
dfs(it.fi, it.se);
special.clear();
for (auto it : all)
for (int g = 0; g < 4; ++g) {
int nr = it.fi + dx[g];
int nc = it.se + dy[g];
if (!in(nr, nc) || (znak != (t[nr][nc] ^ 1)) || odw[nr][nc]) continue;
special.pb(mp(nr, nc));
}
}
printf ("%d\n", ans);
return 0;
}
Compilation message
zoo.cpp: In function 'int main()':
zoo.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &n, &m);
~~~~~~^~~~~~~~~~~~~~~~
zoo.cpp:49:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%s", s[i] + 1);
~~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
3 ms |
1064 KB |
Output is correct |
6 |
Correct |
4 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1020 KB |
Output is correct |
8 |
Correct |
3 ms |
888 KB |
Output is correct |
9 |
Correct |
3 ms |
888 KB |
Output is correct |
10 |
Correct |
3 ms |
1016 KB |
Output is correct |
11 |
Correct |
3 ms |
880 KB |
Output is correct |
12 |
Correct |
3 ms |
888 KB |
Output is correct |
13 |
Correct |
3 ms |
888 KB |
Output is correct |
14 |
Correct |
4 ms |
1016 KB |
Output is correct |
15 |
Correct |
3 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
3 ms |
1064 KB |
Output is correct |
6 |
Correct |
4 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
1020 KB |
Output is correct |
8 |
Correct |
3 ms |
888 KB |
Output is correct |
9 |
Correct |
3 ms |
888 KB |
Output is correct |
10 |
Correct |
3 ms |
1016 KB |
Output is correct |
11 |
Correct |
3 ms |
880 KB |
Output is correct |
12 |
Correct |
3 ms |
888 KB |
Output is correct |
13 |
Correct |
3 ms |
888 KB |
Output is correct |
14 |
Correct |
4 ms |
1016 KB |
Output is correct |
15 |
Correct |
3 ms |
760 KB |
Output is correct |
16 |
Correct |
19 ms |
8052 KB |
Output is correct |
17 |
Correct |
23 ms |
8052 KB |
Output is correct |
18 |
Correct |
18 ms |
8180 KB |
Output is correct |
19 |
Correct |
22 ms |
8048 KB |
Output is correct |
20 |
Correct |
20 ms |
8052 KB |
Output is correct |
21 |
Correct |
72 ms |
7160 KB |
Output is correct |
22 |
Correct |
72 ms |
7368 KB |
Output is correct |
23 |
Correct |
70 ms |
7288 KB |
Output is correct |
24 |
Correct |
74 ms |
7672 KB |
Output is correct |
25 |
Correct |
72 ms |
7492 KB |
Output is correct |
26 |
Correct |
74 ms |
7232 KB |
Output is correct |
27 |
Correct |
70 ms |
7288 KB |
Output is correct |
28 |
Correct |
69 ms |
7160 KB |
Output is correct |
29 |
Correct |
73 ms |
7544 KB |
Output is correct |
30 |
Correct |
74 ms |
7416 KB |
Output is correct |