# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994053 |
2024-06-07T05:13:00 Z |
vjudge1 |
Rima (COCI17_rima) |
C++17 |
|
286 ms |
134852 KB |
#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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
286 ms |
134852 KB |
Output is correct |
5 |
Correct |
39 ms |
856 KB |
Output is correct |
6 |
Correct |
68 ms |
78828 KB |
Output is correct |
7 |
Correct |
70 ms |
78660 KB |
Output is correct |
8 |
Correct |
62 ms |
78420 KB |
Output is correct |
9 |
Correct |
112 ms |
81612 KB |
Output is correct |
10 |
Correct |
65 ms |
78280 KB |
Output is correct |