| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 28305 | tlwpdus 팬클럽 회장 (#68) | Play Onwards (FXCUP2_onward) | C++14 | 103 ms | 2028 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, 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 (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
