답안 #22670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22670 2017-04-30T06:21:43 Z 팀명을 한번 정하면 못바꿀까?(#898, qja0950) Young Zebra (KRIII5_YZ) C++14
0 / 7
33 ms 9360 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], Calc[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, y+M);
		queue<pi> Q; Q.push(s); Vis[x+N][y+M] = true;
		vector<pi> list;

		bool impos = false;
		while(!Q.empty()) {
			int a, b; tie(a, b) = Q.front(); 
			list.push_back(Q.front()); Q.pop();
			if(++Calc[a%N][b%M] >= 2) impos = true;

			for(int k=0; k<4; k++) {
				int na = a + "1012"[k] - '1', nb = b + "0121"[k] - '1';
				if(na < 0 || na >= 3*N || nb < 0 || nb >= 3*M) continue;
				if(Mp[na][nb] != Mp[a][b]) continue;
				if(Vis[na][nb]) continue; Vis[na][nb] = true;
				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:25: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:26: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]);
                                           ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 29 ms 8328 KB Output is partially correct
2 Incorrect 33 ms 9360 KB Output isn't correct
3 Halted 0 ms 0 KB -