# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
475386 | cpp219 | Rima (COCI17_rima) | C++14 | 373 ms | 134744 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>
#define ll int
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
typedef pair<ld,ll> LD;
const ll N = 5e5 + 9;
const ll mod = 1e9 + 7;
const ll base = 31;
ll n,kq;
string s;
struct Trie{
Trie *child[26]; ll have = 0,sz = 0;
void Add(string &s,ll now){
sz += (now == s.size() - 1);
if (now == s.size()){
have = 1; return;
}
ll c = s[now] - 'a';
if (!child[c]) child[c] = new Trie();
child[c] -> Add(s,now + 1);
}
ll GetMax(ll dep){
priority_queue<ll,vector<ll>,greater<ll>> pq; pq.push(0); pq.push(0);
for (ll i = 0;i < 26;i++) if (child[i])
pq.push(child[i] -> GetMax(dep + 1));
while(pq.size() > 2) pq.pop();
ll ans = pq.top(),got = (have > 0 || dep == 0); pq.pop();
//if (sz == 1) debug(got);
kq = max(kq,(ans + pq.top() + sz + have - (ans > 0) - (pq.top() > 0)));
kq = max(kq,(pq.top() + sz + have - (pq.top() > 0)));
//if (kq == 5) debug(sz);
return (pq.top() + sz + 1 - (pq.top() > 0))*got;
}
}Tree;
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
cin>>n;
for (ll i = 1;i <= n;i++){
cin>>s; reverse(s.begin(),s.end());
Tree.Add(s,0);
}
Tree.GetMax(0);
cout<<kq;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |