답안 #27236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27236 2017-07-11T10:52:29 Z 구사과(#1127) Play Onwards (FXCUP2_onward) C++14
1 / 1
36 ms 2192 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, lint> pi;
const int mod = 1e9 + 7;

int n, k;
string str[205];
int adj[205][205], bad;

int dp[25][25], vis[205];

int common(string s, string t){
	int ret = 0;
	for(int i=1; i<=s.size(); i++){
		for(int j=1; j<=t.size(); j++){
			if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
			else dp[i][j] = 0;
			ret = max(ret, dp[i][j]);
		}
	}
	return ret;
}

void dfs(int x, int c){
	if(vis[x]){
		if(vis[x] != c) bad = 1;
		return;
	}
	vis[x] = c;
	for(int i=0; i<n; i++){
		if(adj[x][i]) dfs(i, 3-c);
	}
}

int main(){
	cin >> n >> k;
	for(int i=0; i<n; i++) cin >> str[i];
	bool ok = 0;
	for(int i=0; i<n; i++){
		for(int j=0; j<i; j++){
			if(common(str[i], str[j]) >= k){
				adj[i][j] = adj[j][i] = 1;
				ok = 1;
			}
		}
	}
	if(!ok){
		puts("Yes\n1");
		for(int i=1; i<n; i++) puts("2");
		return 0;
	}
	for(int i=0; i<n; i++){
		if(!vis[i]) dfs(i, 1);
	}
	if(bad) puts("No");
	else{
		puts("Yes");
		for(int i=0; i<n; i++) printf("%d\n", vis[i]);
	}
}

Compilation message

onward.cpp: In function 'int common(std::__cxx11::string, std::__cxx11::string)':
onward.cpp:15:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<=s.size(); i++){
                ^
onward.cpp:16:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=1; j<=t.size(); j++){
                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2192 KB Output is correct
2 Correct 0 ms 2192 KB Output is correct
3 Correct 0 ms 2192 KB Output is correct
4 Correct 0 ms 2192 KB Output is correct
5 Correct 19 ms 2192 KB Output is correct
6 Correct 6 ms 2192 KB Output is correct
7 Correct 9 ms 2192 KB Output is correct
8 Correct 13 ms 2192 KB Output is correct
9 Correct 13 ms 2192 KB Output is correct
10 Correct 9 ms 2192 KB Output is correct
11 Correct 33 ms 2192 KB Output is correct
12 Correct 16 ms 2192 KB Output is correct
13 Correct 16 ms 2192 KB Output is correct
14 Correct 36 ms 2192 KB Output is correct
15 Correct 0 ms 2192 KB Output is correct
16 Correct 0 ms 2192 KB Output is correct
17 Correct 0 ms 2192 KB Output is correct
18 Correct 3 ms 2192 KB Output is correct
19 Correct 6 ms 2192 KB Output is correct
20 Correct 9 ms 2192 KB Output is correct
21 Correct 9 ms 2192 KB Output is correct