답안 #28282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28282 2017-07-16T04:23:04 Z 볼빨간 승관이(#1152, sys7961, deneb2016, hyorothy) Play Onwards (FXCUP2_onward) C++
0 / 1
0 ms 2028 KB
#include<bits/stdc++.h>

int n, k;
char str[210][25];
long long B = 255;
bool connect(int a, int b) {
	int A = strlen(str[a]);
	int B = strlen(str[b]);
	for (int i = 0; i + k < A; i++) {
		for (int j = 0; j + k < B; j++) {
			if (strncmp(str[a] + i, str[b] + j, k) == 0)return true;
		}
	}
	return false;

}
using std::vector;
vector<int> G[210];
int color[210];
bool dfs(int idx) {
	for(int i=0;i<G[idx].size();i++) {
		int to = G[idx][i];
		if (color[to] == 0) {
			color[to] = -color[idx];
			if (!dfs(to)) {
				return false;
			}
		}
		else if (color[to] == color[idx]) {
			return false;
		}
	}
	return true;
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%s", str[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (connect(i, j)) {
				G[i].push_back(j);
				G[j].push_back(i);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (color[i] == 0) {
			color[i] = 1;
			if (!dfs(i)) {
				printf("No");
				return 0;
			}
		}
	}
	printf("Yes\n");
	for (int i = 0; i < n; i++) {
		if (color[i] == -1) {
			printf("2\n");
		}
		else {
			printf("1\n");
		}
	}

}

Compilation message

onward.cpp: In function 'bool dfs(int)':
onward.cpp:21:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<G[idx].size();i++) {
               ^
onward.cpp: In function 'int main()':
onward.cpp:36:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
onward.cpp:38:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", str[i]);
                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 0 ms 2028 KB Output is correct
3 Correct 0 ms 2028 KB Output is correct
4 Correct 0 ms 2028 KB Output is correct
5 Incorrect 0 ms 2028 KB Output isn't correct
6 Halted 0 ms 0 KB -