#include <bits/stdc++.h>
using namespace std;
int n, k;
char str[210][22];
int len[210];
vector<int> lis[210];
int mlen(int n, char str[], int m, char ttr[]) {
int i, j, k, res = 0;
i = 0;
for (j=0;j<m;j++) {
int p = 0;
for (k=0;k<m-j&&k<n-i;k++) {
if (str[i+k]==ttr[j+k]) {
res = max(res,k-p+1);
}
else {
p = k+1;
}
}
}
j = 0;
for (i=0;i<n;i++) {
int p = 0;
for (k=0;k<m-j&&k<n-i;k++) {
if (str[i+k]==ttr[j+k]) {
res = max(res,k-p+1);
}
else {
p = k+1;
}
}
}
return res;
}
bool flag = 1;
int col[210];
void dfs(int here, int p, int c) {
col[here] = c;
for (auto &there : lis[here]) {
if (col[there]) {
if (col[there]==3-c) {
}
else {
flag = 0;
}
continue;
}
dfs(there,here,3-c);
}
}
int main() {
int i, j;
scanf("%d%d",&n,&k);
for (i=0;i<n;i++) {
scanf("%s",str[i]);
len[i] = strlen(str[i]);
}
for (i=0;i<n;i++) {
for (j=0;j<n;j++) {
if (i==j) continue;
if (mlen(len[i],str[i],len[j],str[j])>=k) {
lis[i].push_back(j);
}
}
}
for (i=0;i<n;i++) {
if (col[i]) continue;
dfs(i,-1,1);
}
if (!flag) {
printf("No\n");
return 0;
}
int cnt[3] = {0,0,0};
for (i=0;i<n;i++) {
cnt[col[i]]++;
}
printf("Yes\n");
if (cnt[1]==0) {
printf("1\n");
for (i=1;i<n;i++) printf("2\n");
}
else if (cnt[2]==0) {
printf("2\n");
for (i=1;i<n;i++) printf("1\n");
}
else {
for (i=0;i<n;i++) printf("%d\n",col[i]);
}
return 0;
}
Compilation message
onward.cpp: In function 'int main()':
onward.cpp:60:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&k);
^
onward.cpp:62:21: 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 |
Correct |
33 ms |
2292 KB |
Output is correct |
6 |
Correct |
9 ms |
2292 KB |
Output is correct |
7 |
Correct |
23 ms |
2028 KB |
Output is correct |
8 |
Correct |
23 ms |
2028 KB |
Output is correct |
9 |
Correct |
19 ms |
2028 KB |
Output is correct |
10 |
Correct |
13 ms |
2028 KB |
Output is correct |
11 |
Correct |
119 ms |
2028 KB |
Output is correct |
12 |
Correct |
46 ms |
2028 KB |
Output is correct |
13 |
Correct |
63 ms |
2028 KB |
Output is correct |
14 |
Correct |
89 ms |
2028 KB |
Output is correct |
15 |
Correct |
0 ms |
2028 KB |
Output is correct |
16 |
Correct |
0 ms |
2028 KB |
Output is correct |
17 |
Correct |
0 ms |
2028 KB |
Output is correct |
18 |
Correct |
6 ms |
2028 KB |
Output is correct |
19 |
Correct |
13 ms |
2028 KB |
Output is correct |
20 |
Correct |
19 ms |
2028 KB |
Output is correct |
21 |
Correct |
16 ms |
2028 KB |
Output is correct |