Submission #22689

# Submission time Handle Problem Language Result Execution time Memory
22689 2017-04-30T06:34:52 Z 팀명을 한번 정하면 못바꿀까?(#898, qja0950) Young Zebra (KRIII5_YZ) C++14
7 / 7
59 ms 10020 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <string.h>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<int, int> pi;

const int MAX_N = 4e2 + 10;

int N, M;
char Mp[MAX_N*3][MAX_N*3];
int Chk[MAX_N][MAX_N];
pi Last[MAX_N][MAX_N];
bool Vis[MAX_N*3][MAX_N*3];

int main() {
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; i++) scanf("%s", Mp[i]);
	for(int i=0; i<3*N; i++) for(int j=0; j<3*M; j++) Mp[i][j] = Mp[i%N][j%M];
	for(int x=0; x<N; x++) for(int y=0; y<M; y++) {
		if(Chk[x][y] != 0) continue;

		pi s = make_pair(x+N*1000, y+M*1000);
		queue<pi> Q; Q.push(s); Vis[x][y] = true; Last[x][y] = s;
		vector<pi> list;

		bool impos = false;
		while(!Q.empty()) {
			int a, b; tie(a, b) = Q.front(); 
			list.push_back(Q.front()); Q.pop();

			for(int k=0; k<4; k++) {
				int na = a + "1012"[k] - '1', nb = b + "0121"[k] - '1';
				if(Mp[na%N][nb%M] != Mp[a%N][b%M]) continue;
				if(Vis[na%N][nb%M]) {
					if(Last[na%N][nb%M] != make_pair(na, nb))
						impos = true;
					continue;
				}
				Vis[na%N][nb%M] = true;
				Last[na%N][nb%M] = make_pair(na, nb);
				Q.push(make_pair(na, nb));
			}
		}
		int val = list.size(); if(impos) val = -1;
		for(pi &e : list) Chk[e.first%N][e.second%M] = val;
	}
	for(int i=0; i<N; i++, puts("")) for(int j=0; j<M; j++) printf("%d ", Chk[i][j]);
	return 0;
}

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:26: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:27:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<N; i++) scanf("%s", Mp[i]);
                                           ^
# Verdict Execution time Memory Grader output
1 Correct 33 ms 10016 KB Output is correct
2 Correct 33 ms 8480 KB Output is correct
3 Correct 33 ms 8480 KB Output is correct
4 Correct 36 ms 7964 KB Output is correct
5 Correct 33 ms 7960 KB Output is correct
6 Correct 36 ms 7452 KB Output is correct
7 Correct 36 ms 8988 KB Output is correct
8 Correct 36 ms 8988 KB Output is correct
9 Correct 36 ms 8988 KB Output is correct
10 Correct 36 ms 8988 KB Output is correct
11 Correct 29 ms 10020 KB Output is correct
12 Correct 39 ms 10016 KB Output is correct
13 Correct 33 ms 8984 KB Output is correct
14 Correct 43 ms 8988 KB Output is correct
15 Correct 46 ms 8988 KB Output is correct
16 Correct 36 ms 8988 KB Output is correct
17 Correct 33 ms 8984 KB Output is correct
18 Correct 33 ms 8480 KB Output is correct
19 Correct 49 ms 6860 KB Output is correct
20 Correct 53 ms 8484 KB Output is correct
21 Correct 59 ms 8480 KB Output is correct
22 Correct 39 ms 8988 KB Output is correct
23 Correct 46 ms 8484 KB Output is correct
24 Correct 43 ms 8480 KB Output is correct
25 Correct 36 ms 7712 KB Output is correct
26 Correct 0 ms 6860 KB Output is correct
27 Correct 0 ms 6860 KB Output is correct
28 Correct 0 ms 7000 KB Output is correct
29 Correct 0 ms 7000 KB Output is correct
30 Correct 0 ms 6860 KB Output is correct
31 Correct 0 ms 6860 KB Output is correct
32 Correct 0 ms 6860 KB Output is correct
33 Correct 0 ms 6860 KB Output is correct
34 Correct 0 ms 6860 KB Output is correct
35 Correct 0 ms 6860 KB Output is correct
36 Correct 3 ms 7132 KB Output is correct
37 Correct 3 ms 7132 KB Output is correct
38 Correct 3 ms 6860 KB Output is correct
39 Correct 3 ms 7132 KB Output is correct
40 Correct 0 ms 7132 KB Output is correct