This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 1005;
int t, fix[N][N], n, m;
char a[N][N];
vector<pair<int, int> > next1, cur;
bool ok(int i, int j) {
if (min(i, j) < 1 || i > n || j > m) return 0;
return 1;
}
void dfs(int i, int j, char c) {
if (!ok(i, j) || a[i][j] != c || fix[i][j]) return;
fix[i][j] = 1;
next1.push_back({ i,j });
dfs(i + 1, j, c);
dfs(i - 1, j, c);
dfs(i, j - 1, c);
dfs(i, j + 1, c);
}
main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
dfs(1, 1, a[1][1]);
cur = next1;
next1.clear();
char c = a[1][1];
int ans = 0;
while (cur.size()) {
ans++;
c = 'T' + 'B' - c;
for (int k = 0; k < cur.size(); k++) {
int i = cur[k].f, j = cur[k].s;
dfs(i + 1, j, c);
dfs(i - 1, j, c);
dfs(i, j - 1, c);
dfs(i, j + 1, c);
}
cur = next1;
next1.clear();
}
cout << ans;
}
Compilation message (stderr)
zoo.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
22 | main() {
| ^~~~
zoo.cpp: In function 'int main()':
zoo.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int k = 0; k < cur.size(); k++) {
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |