# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1100410 | codexistent | Rima (COCI17_rima) | C++14 | 328 ms | 147272 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;
#define ll long long
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
struct Trie{
Trie *nx[26];
ll val, ct;
Trie(){
FOR(i, 0, 25) nx[i] = NULL;
val = ct = 0;
}
};
ll n, r = 0;
Trie trie;
void dfs(Trie *ti){
ll chi = 0, b = -1, b2 = -1;
FOR(i, 0, 25){
if(ti->nx[i]){
dfs(ti->nx[i]);
if(ti->nx[i]->ct){
chi++;
if(b <= ti->nx[i]->val){
b2 = b, b = ti->nx[i]->val;
}else if(b2 <= ti->nx[i]->val){
b2 = ti->nx[i]->val;
}
}
}
if(!chi){
ti->val = ti->ct;
}else{
ti->val = max(ti->val, ti->ct + b + chi - 1);
}
r = max(r, ti->val);
if(chi > 1){
r = max(r, ti->ct + b + b2 + chi - 2);
}
}
}
int main(){
cin >> n;
FOR(i, 1, n){
string s; cin >> s;
reverse(begin(s), end(s));
Trie *ctrie = ≜
for(char c : s){
if(!(ctrie->nx[c - 'a'])){
ctrie->nx[c - 'a'] = new Trie();
}
ctrie = ctrie->nx[c - 'a'];
}
ctrie->ct++;
}
dfs(&trie);
cout << r << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |