# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994053 | vjudge1 | Rima (COCI17_rima) | C++17 | 286 ms | 134852 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;
struct node
{
node * ch[26] = {NULL};
bool e = false;
int dp;
int dfs()
{
//cerr << "I'm" << endl;
int ans = 0;
int mx[2] = {0};
dp = e;
for(int i = 0; i < 26; i++)
{
if(ch[i] == NULL) continue;
// cerr << "---> " << char(i + 'a') << endl;
ans = max(ans, ch[i]->dfs());
// cerr << ch[i] -> dp << endl;
// cerr << "<---" << char(i + 'a') << endl;
if(ch[i] -> e)
{
mx[1] = max(mx[1], ch[i]->dp - 1);
if(mx[0] < mx[1]) swap(mx[0], mx[1]);
dp++;
}
}
dp += mx[0];
ans = max(ans, dp + mx[1]);
return ans;
}
};
struct Trie
{
node * root;
Trie() {
root = new node();
}
void insert(string &s)
{
node *cur = root;
for(int i = s.size() - 1; i >= 0; i--)
{
int idx = s[i] - 'a';
if(cur -> ch[idx] == NULL)
cur -> ch[idx] = new node();
cur = cur -> ch[idx];
}
cur -> e = true;
}
int compute()
{
return root->dfs();
}
} T;
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i ++)
{
string s;
cin >> s;
T.insert(s);
}
cout << T.compute() << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |