# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74353 | khsoo01 | Play Onwards (FXCUP2_onward) | C++11 | 11 ms | 968 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |