이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |