Submission #182413

#TimeUsernameProblemLanguageResultExecution timeMemory
182413XmtosXRima (COCI17_rima)C++17
42 / 140
1088 ms159476 KiB
#include <bits/stdc++.h> using namespace std; int n,ans; string s[500004]; vector <int> v[500004]; unordered_map<string, int> r; bool vis[500004],fin[500004]; int dfs (int x) { vis[x]=true; fin[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=1;i<=n;i++) { cin >>s[i]; reverse(s[i].begin(),s[i].end()); r[s[i]]=i; } for (int i=1;i<=n;i++) { for (int j='a';j<='z';j++) { s[i]+=j; if (r[s[i]]) { v[i].push_back(r[s[i]]); v[r[s[i]]].push_back(i); } s[i].pop_back(); } char c= s[i].back(); s[i].pop_back(); for (int j='a';j<='z';j++) { s[i]+=j; if (r[s[i]]) { v[i].push_back(r[s[i]]); } s[i].pop_back(); } s[i]+=c; } for (int i=1;i<=n;i++) { if (!fin[i]) ans=max(ans,dfs(i)+1); } cout <<ans; return 0; }

Compilation message (stderr)

rima.cpp: In function 'int dfs(int)':
rima.cpp:13: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...