Submission #22693

# Submission time Handle Problem Language Result Execution time Memory
22693 2017-04-30T06:36:55 Z 최숭실(#962, eldkqmfhf123, youngjeong_yu, choiking10) Young Zebra (KRIII5_YZ) C++11
0 / 7
500 ms 220340 KB
#include <cstdio>
#define LIM 5
#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 309 ms 169820 KB Output is correct
2 Execution timed out 500 ms 220340 KB Execution timed out
3 Halted 0 ms 0 KB -