답안 #140127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
140127 2019-08-02T07:13:46 Z rdd6584 Young Zebra (KRIII5_YZ) C++14
0 / 7
63 ms 18040 KB
#include <cstdio>
using namespace std;

char b[1201][1202];
int ans[1201][1201], prt[1201][1201];
int rgo[4] = { 1,0,-1,0 }, cgo[4] = { 0,1,0,-1 };
int n, m;
void copy(int r,int c) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			b[i + r][j + c] = b[i][j];
	}
}
int dfs(int r, int c, int w) {
	int ret = 0;
	bool flag = false;
	ans[r][c] = w;
	for (int i = 0; i < 4; i++) {
		int nr = rgo[i] + r, nc = c + cgo[i];
		if (nr < 0 || nc < 0 || nr >= 3 * n || nc >= 3 * m) 
			return -1;
		if (b[r][c] != b[nr][nc] || ans[nr][nc]) continue;
		int df = dfs(nr, nc, w);
		if (df != -1)ret += df;
		else {
			ret = -1;
			break;
		}
	}
	if (ret == -1) return -1;
	else return ret + 1;
}
void dd(int r, int c, int val) {
	prt[r][c] = val;
	for (int i = 0; i < 4; i++) {
		int nr = rgo[i] + r, nc = c + cgo[i];
		if (nr < 0 || nc < 0 || nr >= 3 * n || nc >= 3 * m) continue;
		if (prt[nr][nc]) continue;
		if (ans[r][c] == ans[nr][nc]) dd(nr, nc, val);
	}
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%s", b[i]);
	}
	copy(n, 0); copy(2 * n, 0);
	copy(0, m); copy(0, 2 * m);
	copy(n, m); copy(n, 2 * m);
	copy(2 * n, m); copy(2 * n, 2 * m);

	int cnt = 0;
	for (int i = n; i < 2 * n; i++) {
		for (int j = m; j < 2 * m; j++) {
			if (!ans[i][j]) {
				dd(i, j, dfs(i, j, ++cnt));
			}
		}
	}
	for (int i = n; i < 2 * n; i++) {
		for (int j = m; j < 2 * m; j++) {
			printf("%d ", prt[i][j]);
		}
		printf("\n");
	}
}

Compilation message

YZ.cpp: In function 'int dfs(int, int, int)':
YZ.cpp:16:7: warning: unused variable 'flag' [-Wunused-variable]
  bool flag = false;
       ^~~~
YZ.cpp: In function 'int main()':
YZ.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
YZ.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", b[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 63 ms 18040 KB Output is partially correct
2 Incorrect 63 ms 12664 KB Output isn't correct
3 Halted 0 ms 0 KB -