이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define N (int)20
int cnt, n, m, used[N][N], deg[N][N];
char a[N][N], b[N][N];
void dfs(int i, int j) {
used[i][j] = cnt;
if(b[i][j] == '0') {
int ni = i, nj = j - 1;
if(ni >= 0 && ni < n && nj >= 0 && nj < m) dfs(ni, nj);
}
if(b[i][j+1] == '0') {
int ni = i, nj = j + 1;
if(ni >= 0 && ni < n && nj >= 0 && nj < m) dfs(ni, nj);
}
if(a[i][j] == '0') {
int ni = i-1, nj = j;
if(ni >= 0 && ni < n && nj >= 0 && nj < m) dfs(ni, nj);
}
if(a[i+1][j] == '0') {
int ni = i+1, nj = j;
if(ni >= 0 && ni < n && nj >= 0 && nj < m) dfs(ni, nj);
}
}
signed main () {
cnt = 1;
scanf("%d%d", &n, &m);
for(int i = 0; i <= n; i ++) {
for(int j = 0; j < m; j ++) std::cin >> a[i][j];
}
for(int i = 0; i < n; i ++) {
for(int j = 0; j <= m; j ++) std::cin >> b[i][j];
}
for(int i = 0; i < n; i ++ ) {
for(int j = 0; j < m; j ++) {
deg[i][j] += (a[i][j] == '1') + (a[i+1][j] == '1') + (b[i][j] == '1') + (b[i][j + 1] == '1');
}
}
for(int i = 0; i < n; i ++) {
for(int j = 0; j < m; j ++) {
if(used[i][j] || deg[i][j] == 4) continue;
dfs(i, j);
cnt ++;
}
}
int cnt1 = 0, cnt2 = 0;
for(int i = 0; i < n; i ++) {
for(int j = 0; j < m; j ++) {
if(used[i][j] == 1) cnt1 ++;
else if(used[i][j] == 2) cnt2 ++;
}
}
if(std::min(cnt1, cnt2) == 0) printf("%d", -std::max(cnt1, cnt2));
else
printf("%d", std::max(cnt1, cnt2) - std::min(cnt1, cnt2));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In function 'int main()':
game.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |