Submission #28687

#TimeUsernameProblemLanguageResultExecution timeMemory
28687:thinking_face: (#68)Play Onwards (FXCUP2_onward)C++98
0 / 1
0 ms2028 KiB
#include<bits/stdc++.h> using namespace std; int n, k; vector<string> v; vector<int> graph[200]; int color[200]; bool check(int i, int j) { if(v[i].size() < k || v[j].size() < k) return false; for(int ii = 0; ii <= v[i].size()-k; ii++) for(int jj = 0; jj <= v[j].size()-k; jj++) if(v[i].substr(ii, k) == v[j].substr(jj, k)) return true; return false; } void dfs(int idx, int c) { color[idx] = c; for(int it: graph[idx]) { if(color[it] == c) { printf("No\n"); exit(0); } if(color[it] == -1) dfs(it, !c); } } int main() { cin >> n >> k; for(int i = 0; i < n; i++) { string str; cin >> str; v.push_back(str); } for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) if(check(i, j)) { graph[i].push_back(j); graph[j].push_back(i); } memset(color, -1, sizeof(color)); for(int i = 0; i < n; i++) if(color[i] == -1) dfs(i, 0); bool check = false; for(int i = 0; i < n; i++) if(color[i] == 1) check = true; if(!check) color[0] = 1; printf("Yes\n"); for(int i = 0; i < n; i++) printf("%d\n", color[i]+1); return 0; }

Compilation message (stderr)

onward.cpp: In function 'bool check(int, int)':
onward.cpp:12:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(v[i].size() < k || v[j].size() < k) return false;
                 ^
onward.cpp:12:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(v[i].size() < k || v[j].size() < k) return false;
                                    ^
onward.cpp:14:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int ii = 0; ii <= v[i].size()-k; ii++)
                     ^
onward.cpp:15:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int jj = 0; jj <= v[j].size()-k; jj++)
                      ^
onward.cpp: In function 'void dfs(int, int)':
onward.cpp:25:14: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
  for(int it: graph[idx])
              ^
onward.cpp:27:14: warning: 'it' is used uninitialized in this function [-Wuninitialized]
   if(color[it] == c)
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...