# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28307 | 2017-07-16T04:35:26 Z | tlwpdus 팬클럽 회장(#1123, kdh9949) | Play Onwards (FXCUP2_onward) | C++14 | 99 ms | 2028 KB |
#include <bits/stdc++.h> using namespace std; int n, k, p[401], c[401]; char str[201][22]; int fnd(int x){ return p[x] = (p[x] == x ? x : fnd(p[x])); } void uni(int x, int y){ p[fnd(x)] = fnd(y); } int f(int x, int y){ int ret = 0; for(int i = 0; str[x][i]; i++){ for(int j = 0; str[y][j]; j++){ int t; for(t = 0; str[x][i + t] && str[y][j + t]; t++) if(str[x][i + t] != str[y][j + t]) break; ret = max(ret, t); } } return ret; } int main(){ scanf("%d%d", &n, &k); iota(p + 1, p + 2 * n + 1, 1); for(int i = 1; i <= n; i++){ scanf("%s", str[i]); for(int j = 1; j < i; j++){ if(f(i, j) >= k){ uni(i + n, j); uni(i, j + n); } } } for(int i = 1; i <= n; i++){ if(fnd(i) == fnd(i + n)){ puts("No"); return 0; } } puts("Yes"); for(int i = 1; i <= n; i++){ if(c[fnd(i)]){ printf("%d\n", c[fnd(i)]); c[fnd(i + n)] = 3 - c[fnd(i)]; } else if(c[fnd(i + n)]){ printf("%d\n", 3 - c[fnd(i + n)]); c[fnd(i)] = 3 - c[fnd(i + n)]; } else{ c[fnd(i)] = 1 + (i == n); c[fnd(i + n)] = 2 - (i == n); printf("%d\n", c[fnd(i)]); } } }
Compilation message
# | Verdict | Execution time | Memory | 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 | 99 ms | 2028 KB | Output is correct |
6 | Correct | 6 ms | 2028 KB | Output is correct |
7 | Correct | 13 ms | 2028 KB | Output is correct |
8 | Correct | 13 ms | 2028 KB | Output is correct |
9 | Correct | 13 ms | 2028 KB | Output is correct |
10 | Correct | 9 ms | 2028 KB | Output is correct |
11 | Correct | 83 ms | 2028 KB | Output is correct |
12 | Correct | 26 ms | 2028 KB | Output is correct |
13 | Correct | 46 ms | 2028 KB | Output is correct |
14 | Correct | 66 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 | 19 ms | 2028 KB | Output is correct |
19 | Correct | 6 ms | 2028 KB | Output is correct |
20 | Correct | 13 ms | 2028 KB | Output is correct |
21 | Correct | 13 ms | 2028 KB | Output is correct |