# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28674 | Fe (#68) | Play Onwards (FXCUP2_onward) | C++98 | 9 ms | 1492 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<string.h>
#define N 205
int n,k,net[N][N],b[N][N],drg[N],chk[N],m[N],f[N],cnt;
char s[N][N];
int kmp(int x,int y,int ss,int e){
int i,j;
i=j=0;
while(i<m[y]){
while(j+1 && s[y][i]-s[x][j+ss]) j=f[j];
i++;j++;
if(j==k) return 1;
}
return 0;
}
void make_f(int x,int ss,int e){
int i,j;
i=0;j=-1;
f[i]=j;
while(i<k){
while(j+1 && s[x][i+ss]-s[x][j+ss]) j=f[j];
i++;j++;
f[i]=j;
}
}
int is_ok(int x,int y){
int ss,e,i,j;
for(ss=0;ss<m[x]-k+1;ss++){
e=ss+k-1;
make_f(x,ss,e);
if(kmp(x,y,ss,e)) return 1;
}
return 0;
}
int main(){
int i,j,h;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++){
scanf("%s",s[i]);
m[i]=strlen(s[i]);
}
for(i=1;i<=n;i++){
for(j=i+1;j<=n;j++){
if(is_ok(i,j)) continue;
net[i][j]=net[j][i]=1;
}
}
cnt=0;
for(i=1;i<=n;i++){
if(chk[i]) continue;
chk[i]=++cnt;
b[cnt][drg[cnt]++]=i;
for(j=i+1;j<=n;j++){
if(chk[j]) continue;
for(h=0;h<drg[cnt];h++){
if(!net[j][b[cnt][h]]) break;
}
if(h-drg[cnt]) continue;
chk[j]=cnt;
b[cnt][drg[cnt]++]=j;
}
}
if(cnt==1){
printf("Yes\n");
printf("2\n");
for(i=2;i<=n;i++) printf("1\n");
}else if(cnt==2){
printf("Yes\n");
for(i=1;i<=n;i++) printf("%d\n",chk[i]);
}else{
printf("No\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |