| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 28307 | tlwpdus 팬클럽 회장 (#68) | Play Onwards (FXCUP2_onward) | C++14 | 99 ms | 2028 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 + (i == n);
c[fnd(i + n)] = 2 - (i == n);
printf("%d\n", c[fnd(i)]);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
