답안 #22483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22483 2017-04-30T05:02:38 Z 카시코이(#958, xdoju, ntopia, pps789) Young Zebra (KRIII5_YZ) C++
2 / 7
56 ms 113144 KB
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;

int n, m;
char board[2603][2603];
int visit[2603][2603];
int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
int outlist[20000000];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			scanf(" %c", &board[i][j]);
		}
	}
	for (int i = 0; i < n * 3; ++i) {
		for (int j = 0; j < m * 3; ++j) {
			board[i][j] = board[i % n][j % m];
		}
	}

	int cur = 0;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (visit[i][j] != 0) continue;

			++cur;
			int cnt = 0;
			queue<pair<int, int> > q;
			visit[i][j] = cur;
			q.push(make_pair(i, j));
			while (!q.empty()) {
				int ci = q.front().first, cj = q.front().second;
				q.pop();
				++cnt;

				for (int k = 0; k < 4; ++k) {
					int ni = (ci + di[k] + n) % n, nj = (cj + dj[k] + m) % m;
					if (visit[ni][nj] != 0) continue;
					if (board[ni][nj] != board[i][j]) continue;
					visit[ni][nj] = cur;
					q.push(make_pair(ni, nj));
				}
			}

			outlist[cur] = cnt;
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			int out = outlist[visit[i][j]];
			printf("%d ", out);
		}
		printf("\n");
	}
	return 0;
}

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:17:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
                        ^
YZ.cpp:20:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &board[i][j]);
                              ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 36 ms 113144 KB Output is partially correct
2 Partially correct 33 ms 113144 KB Output is partially correct
3 Partially correct 39 ms 113144 KB Output is partially correct
4 Partially correct 56 ms 113144 KB Output is partially correct
5 Partially correct 43 ms 113144 KB Output is partially correct
6 Partially correct 29 ms 113144 KB Output is partially correct
7 Partially correct 33 ms 113144 KB Output is partially correct
8 Partially correct 39 ms 113144 KB Output is partially correct
9 Partially correct 39 ms 113144 KB Output is partially correct
10 Partially correct 43 ms 113144 KB Output is partially correct
11 Partially correct 33 ms 113144 KB Output is partially correct
12 Partially correct 26 ms 113144 KB Output is partially correct
13 Partially correct 43 ms 113144 KB Output is partially correct
14 Partially correct 46 ms 113144 KB Output is partially correct
15 Partially correct 39 ms 113144 KB Output is partially correct
16 Partially correct 33 ms 113144 KB Output is partially correct
17 Partially correct 33 ms 113144 KB Output is partially correct
18 Partially correct 46 ms 113144 KB Output is partially correct
19 Correct 46 ms 113144 KB Output is correct
20 Partially correct 43 ms 113144 KB Output is partially correct
21 Partially correct 53 ms 113144 KB Output is partially correct
22 Partially correct 36 ms 113144 KB Output is partially correct
23 Partially correct 56 ms 113144 KB Output is partially correct
24 Partially correct 46 ms 113144 KB Output is partially correct
25 Partially correct 39 ms 113144 KB Output is partially correct
26 Partially correct 0 ms 113144 KB Output is partially correct
27 Partially correct 0 ms 113144 KB Output is partially correct
28 Partially correct 0 ms 113144 KB Output is partially correct
29 Partially correct 0 ms 113144 KB Output is partially correct
30 Partially correct 0 ms 113144 KB Output is partially correct
31 Partially correct 0 ms 113144 KB Output is partially correct
32 Partially correct 0 ms 113144 KB Output is partially correct
33 Partially correct 0 ms 113144 KB Output is partially correct
34 Partially correct 0 ms 113144 KB Output is partially correct
35 Partially correct 0 ms 113144 KB Output is partially correct
36 Partially correct 0 ms 113144 KB Output is partially correct
37 Partially correct 3 ms 113144 KB Output is partially correct
38 Correct 0 ms 113144 KB Output is correct
39 Partially correct 3 ms 113144 KB Output is partially correct
40 Partially correct 0 ms 113144 KB Output is partially correct