# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1096869 |
2024-10-05T10:03:36 Z |
vjudge1 |
Rima (COCI17_rima) |
C++17 |
|
233 ms |
134740 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=5e5+5;
const ll inf=2e18;
int n,ans=0;
struct Node
{
Node *child[26];
int val,cnt;
Node()
{
for(int i=0;i<26;i++)
{
child[i]=NULL;
}
val=0;
cnt=0;
}
};
Node root;
struct Trie
{
void add(string s)
{
Node *cur=&root;
for(auto c:s)
{
int d=(c-'a');
if(!(cur->child[d]))
{
cur->child[d]=new Node();
}
cur=cur->child[d];
}
cur->cnt++;
}
void dfs(Node *u)
{
vector<int> vec;
for(int i=0;i<26;i++)
{
if(u->child[i])
{
dfs(u->child[i]);
if(u->child[i]->cnt)
{
vec.push_back(u->child[i]->val);
}
}
}
sort(vec.begin(),vec.end(),greater<int>());
int m=vec.size();
if(!m)
{
u->val=u->cnt;
}
else u->val=max(u->val,u->cnt+vec[0]+m-1);
ans=max(ans,u->val);
if(m>1)
{
ans=max(ans,u->cnt+vec[0]+vec[1]+m-2);
}
}
}f;
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
reverse(s.begin(),s.end());
f.add(s);
}
f.dfs(&root);
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
233 ms |
134740 KB |
Output is correct |
5 |
Correct |
10 ms |
1112 KB |
Output is correct |
6 |
Correct |
60 ms |
90264 KB |
Output is correct |
7 |
Correct |
59 ms |
90040 KB |
Output is correct |
8 |
Correct |
64 ms |
90208 KB |
Output is correct |
9 |
Correct |
74 ms |
93020 KB |
Output is correct |
10 |
Correct |
59 ms |
90028 KB |
Output is correct |