# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
229674 | MohamedAhmed04 | Rima (COCI17_rima) | C++14 | 304 ms | 166648 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std ;
const int MAX = 3e6 + 10 ;
string arr[MAX] ;
int n ;
int tree[MAX][27] , Cnt[MAX] , dp[MAX] , finished[MAX] ;
int last = 0 ;
void Insert(string s)
{
int node = 0 ;
for(int i = 0 ; i < s.size() ; ++i)
{
if(i == s.size()-1)
Cnt[node]++ ;
char c = s[i] ;
int idx = c - 'a' ;
if(!tree[node][idx])
tree[node][idx] = ++last ;
node = tree[node][idx] ;
}
finished[node] = 1 ;
}
int ans = 0 ;
void solve(int node)
{
pair<int , int>p = {0 , 0} ;
pair<int , int>p2 ;
for(int i = 0 ; i < 26 ; ++i)
{
if(!tree[node][i])
continue ;
int child = tree[node][i] ;
solve(child) ;
p2 = {max(p.first, dp[child]), min(p.first, dp[child])} ;
p = max(p , p2) ;
}
ans = max(ans , p.first+p.second+Cnt[node]+finished[node]) ;
dp[node] = p.first + Cnt[node] ;
if(!finished[node])
dp[node] = 0 ;
return ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n ;
for(int i = 0 ; i < n ; ++i)
{
cin>>arr[i] ;
reverse(arr[i].begin() , arr[i].end()) ;
Insert(arr[i]) ;
}
solve(0) ;
return cout<<ans<<"\n" , 0 ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |