Submission #74353

#TimeUsernameProblemLanguageResultExecution timeMemory
74353khsoo01Play Onwards (FXCUP2_onward)C++11
1 / 1
11 ms968 KiB
#include<bits/stdc++.h> using namespace std; int n, k, l[205], vis[205], c[3]; char a[205][25]; vector<int> adj[205]; void solve (int I, int C) { if(vis[I]) return; vis[I] = C; c[C]++; for(auto &T : adj[I]) solve(T, ((C-1)^1)+1); } int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { scanf("%s",a[i]+1); l[i] = strlen(a[i]+1); } for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { if(l[i] < k || l[j] < k) continue; bool flag = 0; for(int A=1;A+k-1<=l[i];A++) { for(int B=1;B+k-1<=l[j];B++) { bool s = 0; for(int C=0;C<k;C++) { if(a[i][A+C] != a[j][B+C]) {s = true; break;} } if(!s) {flag = true; break;} } if(flag) break; } if(flag) { adj[i].push_back(j); adj[j].push_back(i); } } for(int i=1;i<=n;i++) solve(i, 1); for(int i=1;i<=n;i++) { for(auto &T : adj[i]) if(vis[i] == vis[T]) {puts("No"); return 0;} } puts("Yes"); printf("%d\n",1+(c[1]==n)); for(int i=2;i<=n;i++) printf("%d\n",vis[i]); }

Compilation message (stderr)

onward.cpp: In function 'int main()':
onward.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
onward.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",a[i]+1);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...