# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74353 | 2018-08-31T11:00:40 Z | khsoo01 | Play Onwards (FXCUP2_onward) | C++11 | 11 ms | 968 KB |
#include<bits/stdc++.h> using namespace std; int n, k, l[205], vis[205], c[3]; char a[205][25]; vector<int> adj[205]; void solve (int I, int C) { if(vis[I]) return; vis[I] = C; c[C]++; for(auto &T : adj[I]) solve(T, ((C-1)^1)+1); } int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { scanf("%s",a[i]+1); l[i] = strlen(a[i]+1); } for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { if(l[i] < k || l[j] < k) continue; bool flag = 0; for(int A=1;A+k-1<=l[i];A++) { for(int B=1;B+k-1<=l[j];B++) { bool s = 0; for(int C=0;C<k;C++) { if(a[i][A+C] != a[j][B+C]) {s = true; break;} } if(!s) {flag = true; break;} } if(flag) break; } if(flag) { adj[i].push_back(j); adj[j].push_back(i); } } for(int i=1;i<=n;i++) solve(i, 1); for(int i=1;i<=n;i++) { for(auto &T : adj[i]) if(vis[i] == vis[T]) {puts("No"); return 0;} } puts("Yes"); printf("%d\n",1+(c[1]==n)); for(int i=2;i<=n;i++) printf("%d\n",vis[i]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 480 KB | Output is correct |
3 | Correct | 2 ms | 480 KB | Output is correct |
4 | Correct | 2 ms | 480 KB | Output is correct |
5 | Correct | 3 ms | 740 KB | Output is correct |
6 | Correct | 4 ms | 784 KB | Output is correct |
7 | Correct | 8 ms | 784 KB | Output is correct |
8 | Correct | 8 ms | 784 KB | Output is correct |
9 | Correct | 8 ms | 784 KB | Output is correct |
10 | Correct | 8 ms | 784 KB | Output is correct |
11 | Correct | 2 ms | 784 KB | Output is correct |
12 | Correct | 11 ms | 784 KB | Output is correct |
13 | Correct | 11 ms | 784 KB | Output is correct |
14 | Correct | 5 ms | 784 KB | Output is correct |
15 | Correct | 2 ms | 784 KB | Output is correct |
16 | Correct | 2 ms | 784 KB | Output is correct |
17 | Correct | 2 ms | 784 KB | Output is correct |
18 | Correct | 2 ms | 784 KB | Output is correct |
19 | Correct | 7 ms | 968 KB | Output is correct |
20 | Correct | 7 ms | 968 KB | Output is correct |
21 | Correct | 8 ms | 968 KB | Output is correct |