# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28775 | kriii | Play Onwards (FXCUP2_onward) | C++14 | 9 ms | 1980 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 <stdio.h>
#include <queue>
using namespace std;
int N,K,C[202];
char S[202][22]; bool g[202][202];
int main()
{
scanf ("%d %d",&N,&K);
for (int i=0;i<N;i++) scanf ("%s",S[i]);
for (int i=0;i<N;i++) for (int j=i+1;j<N;j++){
bool d = 0;
for (int p=K-1;S[i][p];p++) for (int q=K-1;S[j][q];q++){
bool n = 1;
for (int r=0;r<K;r++) if (S[i][p-r] != S[j][q-r]){n = 0; break;}
if (n) d = 1;
}
g[i][j] = g[j][i] = d;
}
int u = 0;
for (int i=0;i<N;i++) if (C[i] == 0){
queue<int> Q; Q.push(i); C[i] = u+1; u = !u;
while (!Q.empty()){
int x = Q.front(); Q.pop();
for (int y=0;y<N;y++) if (g[x][y]){
if (C[y] == 0){
Q.push(y); C[y] = 3 - C[x];
}
if (C[x] + C[y] != 3){
puts("No");
return 0;
}
}
}
}
puts("Yes");
for (int i=0;i<N;i++) printf ("%d\n",C[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |