Submission #960543

#TimeUsernameProblemLanguageResultExecution timeMemory
960543LM1Rima (COCI17_rima)C++14
70 / 140
365 ms218752 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N=5e5+5,M=3e6+5; int t,n,dp[M],fix[M][26],ans=1,cn,cnt[M]; vector<int>v[M]; string s; void add(string s){ int cur=0; for(int i=0;i<(int)s.size();i++){ int c=s[i]-'a'; if(!fix[cur][c]){ cn++; fix[cur][c]=cn; v[cur].push_back(fix[cur][c]); } cur=fix[cur][c]; } cnt[cur]++; } void dfs(int st,int p){ if(v[st].size()==0 and st>0){ dp[st]=1; return; } int mx=0; vector<int>v1; for (int i:v[st]){ if (i==p)continue; dfs(i,st); mx=max(mx,dp[i]); if(dp[i])v1.push_back(dp[i]); } sort(v1.begin(),v1.end()); if(v1.size()>=2)ans=max(ans,v1.back()+v1[v1.size()-2]+(int)v1.size()-2); ans=max(ans,mx+(int)v1.size()-(!cnt[st])); if(cnt[st])dp[st]=mx+1+v1.size()-min((int)v1.size(),(int)1); else dp[st]=0; } main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>s; reverse(s.begin(),s.end()); add(s); } dfs(0,0); cout<<ans; }

Compilation message (stderr)

rima.cpp:40:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   40 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...