답안 #28687

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28687 2017-07-16T08:42:49 Z :thinking_face:(#1137, zych1751, Acka, suzy) Play Onwards (FXCUP2_onward) C++
0 / 1
0 ms 2028 KB
#include<bits/stdc++.h>

using namespace std;

int n, k;
vector<string> v;
vector<int> graph[200];
int color[200];

bool check(int i, int j)
{
	if(v[i].size() < k || v[j].size() < k)	return false;

	for(int ii = 0; ii <= v[i].size()-k; ii++)
		for(int jj = 0; jj <= v[j].size()-k; jj++)
			if(v[i].substr(ii, k) == v[j].substr(jj, k))
				return true;
	return false;
}

void dfs(int idx, int c)
{
	color[idx] = c;

	for(int it: graph[idx])
	{
		if(color[it] == c)
		{
			printf("No\n");
			exit(0);
		}

		if(color[it] == -1)
			dfs(it, !c);
	}
}

int main()
{
	cin >> n >> k;

	for(int i = 0; i < n; i++)
	{
		string str;
		cin >> str;
		v.push_back(str);
	}

	for(int i = 0; i < n; i++)
		for(int j = i+1; j < n; j++)
			if(check(i, j))
			{
				graph[i].push_back(j);
				graph[j].push_back(i);
			}
	memset(color, -1, sizeof(color));

	for(int i = 0; i < n; i++)
		if(color[i] == -1)
			dfs(i, 0);

	bool check = false;
	for(int i = 0; i < n; i++)
		if(color[i] == 1)
			check = true;

	if(!check)
		color[0] = 1;

	printf("Yes\n");
	for(int i = 0; i < n; i++)
		printf("%d\n", color[i]+1);
	return 0;
}

Compilation message

onward.cpp: In function 'bool check(int, int)':
onward.cpp:12:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(v[i].size() < k || v[j].size() < k) return false;
                 ^
onward.cpp:12:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(v[i].size() < k || v[j].size() < k) return false;
                                    ^
onward.cpp:14:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int ii = 0; ii <= v[i].size()-k; ii++)
                     ^
onward.cpp:15:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int jj = 0; jj <= v[j].size()-k; jj++)
                      ^
onward.cpp: In function 'void dfs(int, int)':
onward.cpp:25:14: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
  for(int it: graph[idx])
              ^
onward.cpp:27:14: warning: 'it' is used uninitialized in this function [-Wuninitialized]
   if(color[it] == c)
              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Incorrect 0 ms 2028 KB Output isn't correct
3 Halted 0 ms 0 KB -