#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb(x) push_back(x)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define Fi first
#define Se second
char A[220][220];
int n, k;
int E[220][220];
int L[220];
int color[220];
void dfs(int x, int c) {
color[x] = c;
rep(i, n) if(E[x][i]) {
if(color[i] == 0) dfs(i, 3 - c);
}
}
void solve() {
scanf("%d%d", &n, &k);
for(int i=0;i<n;i++) scanf("%s", A[i]);
rep(i, n) L[i] = (int)strlen(A[i]);
rep(i, n) rep(j, i){
for(int u=0;u<=L[i]-k;u++) {
for(int v=0;v<=L[j]-k;v++){
int ok = 1;
for(int a=0;a<k;a++) if(A[i][u+a] != A[j][v+a]) ok = 0;
if(ok){ E[i][j] = E[j][i] = 1; break; }
}
if(E[i][j]) break;
}
}
rep(i, n) if(color[i] == 0) {
dfs(i, 1);
}
rep(i, n) rep(j, n) if(E[i][j] && color[i] == color[j]) {
puts("No");
return;
}
puts("Yes");
if(*min_element(color, color+n) == *max_element(color, color+n)) {
color[1] = 3 - color[0];
}
rep(i, n) printf("%d\n", color[i]);
}
int main(){
int Tc = 1; //scanf("%d", &Tc);
for(int tc=1;tc<=Tc;tc++) {
// printf("Case #%d\n", tc);
solve();
}
return 0;
};
Compilation message
onward.cpp: In function 'void solve()':
onward.cpp:44: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:45:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0;i<n;i++) scanf("%s", A[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2256 KB |
Output is correct |
2 |
Correct |
0 ms |
2256 KB |
Output is correct |
3 |
Correct |
0 ms |
2256 KB |
Output is correct |
4 |
Correct |
0 ms |
2256 KB |
Output is correct |
5 |
Correct |
0 ms |
2256 KB |
Output is correct |
6 |
Correct |
0 ms |
2256 KB |
Output is correct |
7 |
Correct |
9 ms |
2256 KB |
Output is correct |
8 |
Correct |
9 ms |
2256 KB |
Output is correct |
9 |
Correct |
9 ms |
2256 KB |
Output is correct |
10 |
Correct |
9 ms |
2256 KB |
Output is correct |
11 |
Correct |
0 ms |
2256 KB |
Output is correct |
12 |
Correct |
13 ms |
2256 KB |
Output is correct |
13 |
Correct |
13 ms |
2256 KB |
Output is correct |
14 |
Correct |
3 ms |
2256 KB |
Output is correct |
15 |
Correct |
0 ms |
2256 KB |
Output is correct |
16 |
Correct |
0 ms |
2256 KB |
Output is correct |
17 |
Correct |
0 ms |
2256 KB |
Output is correct |
18 |
Correct |
0 ms |
2256 KB |
Output is correct |
19 |
Correct |
6 ms |
2256 KB |
Output is correct |
20 |
Correct |
13 ms |
2256 KB |
Output is correct |
21 |
Correct |
6 ms |
2256 KB |
Output is correct |