답안 #641145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641145 2022-09-16T05:30:17 Z maks007 Game (eJOI20_game) C++14
0 / 100
1 ms 296 KB
#include "bits/stdc++.h"

signed main () {
	int n, m;
	scanf("%d%d", &n, &m);
	char a[n + 1][m], b[n][m + 1];
	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];
	}
	std::queue <std::pair <int,int>> q;
	int used[n][m];
	memset(used, 0, sizeof(used));
	int deg[n][m];
	memset(deg, 0, sizeof(deg));
	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');
		}
	}
	int cnt = 1;
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < m; j ++) {
			if(used[i][j] || deg[i][j] == 4) continue;
			used[i][j] = cnt;
			q.push({i, j});
			while(!q.empty()) {
				std::pair <int,int> v = q.front();
				q.pop();
				if(b[v.first][v.second] != '1') {
					int ni = v.first, nj = v.second-1;
					if(ni >= 0 && ni < n && nj >= 0 && nj < m && !used[ni][nj]) {
						q.push({ni, nj});
						used[ni][nj] = cnt;
					} 
				}
				if(b[v.first][v.second + 1] != '1') {
					int ni = v.first, nj = v.second + 1;
					if(ni >= 0 && ni < n && nj >= 0 && nj < m && !used[ni][nj]) {
						q.push({ni, nj});
						used[ni][nj] = cnt;
					} 
				}
				if(a[v.first][v.second] != '1') {
					int ni = v.first - 1, nj = v.second;
					if(ni >= 0 && ni < n && nj >= 0 && nj < m && !used[ni][nj]) {
						q.push({ni, nj});
						used[ni][nj] = cnt;
					} 
				}
				if(a[v.first + 1][v.second] != '1') {
					int ni = v.first + 1, nj = v.second;
					if(ni >= 0 && ni < n && nj >= 0 && nj < m && !used[ni][nj]) {
						q.push({ni, nj});
						used[ni][nj] = cnt;
					} 
				}
			}
			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 ++;
			// printf("%d ", used[i][j]);
		}
		// printf("\n");
	}
	printf("%d", std::max(cnt1, cnt2) - std::min(cnt1, cnt2));
	return 0;
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:5:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 296 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -