#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;
}
Compilation message
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);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Runtime error |
257 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
221 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
220 KB |
Output is correct |
2 |
Runtime error |
231 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
243 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Runtime error |
257 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |