#include <bits/stdc++.h>
using namespace std;
int N, K, D[22][22];
char A[202][22];
int adj[202][202], num[202];
bool chk;
void add_edge(int x, int y) {
memset(D, 0, sizeof(D));
int alen = strlen(A[x]), blen = strlen(A[y]);
int res = 0;
for(int i=0; i<alen; i++) for(int j=0; j<blen; j++) {
if(A[x][i] != A[y][j]) D[i][j] = 0;
else if(i == 0 || j == 0) D[i][j] = 1;
else D[i][j] = D[i-1][j-1] + 1;
res = max(res, D[i][j]);
}
if(res >= K) adj[x][y] = adj[y][x] = 1;
// printf("%d %d : %d\n", x, y, res);
}
void dfs(int x, int y) {
// printf("%d %d\n", x, y);
num[x] = y;
for(int i=1; i<=N; i++) {
if(!adj[x][i]) continue;
if(num[i] == num[x]) chk = 1;
else if(!num[i]) dfs(i, 3 - y);
}
}
int main() {
scanf("%d %d", &N, &K);
for(int i=1; i<=N; i++) scanf("%s", A[i]);
for(int i=1; i<=N; i++) for(int j=i+1; j<=N; j++) add_edge(i, j);
for(int i=1; i<=N; i++) if(!num[i]) dfs(i, 1);
if(chk) return puts("No"),0;
puts("Yes");
for(int i=1; i<=N; i++) printf("%d\n", num[i]);
}
Compilation message
onward.cpp: In function 'int main()':
onward.cpp:34:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &K);
^
onward.cpp:35:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1; i<=N; i++) scanf("%s", A[i]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2184 KB |
Output is correct |
2 |
Correct |
0 ms |
2184 KB |
Output is correct |
3 |
Correct |
0 ms |
2184 KB |
Output is correct |
4 |
Correct |
0 ms |
2184 KB |
Output is correct |
5 |
Correct |
16 ms |
2184 KB |
Output is correct |
6 |
Correct |
3 ms |
2184 KB |
Output is correct |
7 |
Correct |
9 ms |
2184 KB |
Output is correct |
8 |
Correct |
13 ms |
2184 KB |
Output is correct |
9 |
Correct |
9 ms |
2184 KB |
Output is correct |
10 |
Correct |
6 ms |
2184 KB |
Output is correct |
11 |
Incorrect |
29 ms |
2184 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |