Submission #28307

#TimeUsernameProblemLanguageResultExecution timeMemory
28307tlwpdus 팬클럽 회장 (#68)Play Onwards (FXCUP2_onward)C++14
1 / 1
99 ms2028 KiB
#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)]); } } }

Compilation message (stderr)

onward.cpp: In function 'int main()':
onward.cpp:23:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
onward.cpp:26:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", str[i]);
                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...