# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
718229 |
2023-04-03T17:25:01 Z |
Ahmed57 |
Rima (COCI17_rima) |
C++14 |
|
304 ms |
239964 KB |
#include <bits/stdc++.h>
using namespace std ;
//TRIE
struct node{
node *nxt[26];
int is = 0;
node(){
is = 0;
for(int i = 0;i<26;i++){
nxt[i] = NULL;
}
}
};
void inser(string w,node *root){
for(auto ch:w){
if(root->nxt[ch-'a']==NULL){
root->nxt[ch-'a'] = new node();
}
root=root->nxt[ch-'a'];
}
root->is++;
}
int Nnode = 0;
vector<int> adj[3000001];
int mark[3000001];
void build(node *root){
int cur = Nnode;
for(int j = 0;j<26;j++){
if(root->nxt[j]!=NULL){
Nnode++;
adj[cur].push_back(Nnode);
mark[Nnode] = root->nxt[j]->is;
build(root->nxt[j]);
}
}
}
long long dp[3000001];
long long calc(int node){
if(dp[node]!=-1)return dp[node];
long long ma = 0 , sum = mark[node];
for(auto j:adj[node]){
sum+=mark[j];
}
for(auto j:adj[node]){
if(mark[j]>0){
ma = max(ma,calc(j));
}
}
return dp[node]=ma+sum;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin>>n;
node *root = new node();
while(n--){
string s;cin>>s;
reverse(s.begin(),s.end());
inser(s,root);
}
build(root);
memset(dp,-1,sizeof dp);
long long all =0;
for(int i = 0;i<=Nnode;i++){
if(mark[i]){
all = max(all,calc(i));
}
}
cout<<all<<endl;
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
94284 KB |
Output isn't correct |
2 |
Incorrect |
49 ms |
94236 KB |
Output isn't correct |
3 |
Incorrect |
43 ms |
94264 KB |
Output isn't correct |
4 |
Incorrect |
304 ms |
239964 KB |
Output isn't correct |
5 |
Incorrect |
57 ms |
94988 KB |
Output isn't correct |
6 |
Incorrect |
116 ms |
180564 KB |
Output isn't correct |
7 |
Incorrect |
126 ms |
180448 KB |
Output isn't correct |
8 |
Incorrect |
106 ms |
180272 KB |
Output isn't correct |
9 |
Incorrect |
121 ms |
183668 KB |
Output isn't correct |
10 |
Incorrect |
105 ms |
180212 KB |
Output isn't correct |