Submission #22691

# Submission time Handle Problem Language Result Execution time Memory
22691 2017-04-30T06:35:32 Z 최숭실(#962, eldkqmfhf123, youngjeong_yu, choiking10) Young Zebra (KRIII5_YZ) C++11
0 / 7
159 ms 74448 KB
#include <cstdio>
#define LIM 3
#define EDGE_MIN (LIM - LIM)
#define EDGE_MAX (LIM * 2)
int n, m;
char map[410][410];
int check[410 * (LIM * 2+1)][410 * (LIM * 2 + 1)];
int id[410 * (LIM * 2 + 1)][410 * (LIM * 2 + 1)];
int count[410 * 410];
int xx[] = { 1,-1,0,0 };
int yy[] = { 0,0,1,-1 };

char get_col(int xi, int yi) {
	return map[xi % n][yi % m];
}
int dfs(int xi, int yi, char col, int idx) {
	if (id[xi][yi] != 0) return 0;
	if (xi / n == EDGE_MIN || xi / n == EDGE_MAX ||
		yi / m == EDGE_MAX || yi / m == EDGE_MIN) {
		return -1;
	}
	if(count[idx] != -1) count[idx]++;
	id[xi][yi] = idx;
	for (int i = 0; i < 4; i++) {
		int ni = xi + xx[i], mi = yi + yy[i];
		if (get_col(xi, yi) == get_col(ni, mi)) {
			int val = dfs(ni, mi, col, idx);
			if (val == -1) count[idx] = -1;
		}
	}
	return 0;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
			scanf("%s", map[i]);
		
	}
	int myid = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			dfs(i + n*LIM, j + m*LIM, map[i][j], myid++);
		}
	}
	for (int i = 0; i < n; i++, printf("\n")) {
		for (int j = 0; j < m; j++) {
			printf("%d ", count[id[i+n*LIM][j+m*LIM]]);
		}
	}
}

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:34:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
YZ.cpp:36:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%s", map[i]);
                       ^
# Verdict Execution time Memory Grader output
1 Correct 159 ms 71700 KB Output is correct
2 Incorrect 123 ms 74448 KB Output isn't correct
3 Halted 0 ms 0 KB -