Submission #182409

#TimeUsernameProblemLanguageResultExecution timeMemory
182409XmtosXRima (COCI17_rima)C++17
42 / 140
5 ms504 KiB
#include <bits/stdc++.h> using namespace std; int n,ans; string s[20]; vector <int> v[20]; bool vis[20]; bool check (string s1,string s2) { int x=max(s1.size(),s2.size())-1; return s1.substr(0,x)==s2.substr(0,x); } int dfs (int x) { vis[x]=true; int maxx=0; for (int i=0;i<v[x].size();i++) { if (!vis[v[x][i]]) maxx=max(maxx,dfs(v[x][i])+1); } vis[x]=false; return maxx; } int main() { cin >>n; for (int i=0;i<n;i++) { cin >>s[i]; reverse(s[i].begin(),s[i].end()); } for (int i=0;i<n;i++) { for (int j=i+1;j<n;j++) { if (check(s[i],s[j])) { v[i].push_back(j); v[j].push_back(i); } } } for (int i=0;i<n;i++) ans=max(ans,dfs(i)+1); cout <<ans; return 0; }

Compilation message (stderr)

rima.cpp: In function 'int dfs(int)':
rima.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<v[x].size();i++)
                  ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...