# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28305 | 2017-07-16T04:33:53 Z | tlwpdus 팬클럽 회장(#1123, kdh9949) | Play Onwards (FXCUP2_onward) | C++14 | 103 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; c[fnd(i + n)] = 2; printf("%d\n", 1); } } }
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 | 103 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 | Incorrect | 79 ms | 2028 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |