/// You just can't beat the person who never gives up
/// ICPC next year
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std ;
const int N = 3e6+5 ;
int n ,m ,sz ,en[N] ;
vector<pair<int,int>> to[N] ;
char str[N] ;
void insert_str(){
int cur = 0 ;
for(int i=0;i<m;++i){
int cc = str[i] - 'a' ;
int j = 0 ;
while(j<to[cur].size() && to[cur][j].first!=cc) ++j ;
if(j==to[cur].size()) to[cur].push_back({cc ,++sz}) ;
cur = to[cur][j].second ;
}
++en[cur] ;
}
int mem[N][2] ;
int dfs(int cur,bool is){
int&ret = mem[cur][is];
if(~ret) return ret;
ret = 0 ;
if(!is) for(auto i:to[cur]) ret = max(ret ,dfs(i.second,0)) ;
int here = 0 ;
for(auto i:to[cur]) here += en[i.second] ;
if(!here) return ret ;
ret = max(ret,here) ;
for(auto i:to[cur]) if(en[i.second]) ret = max(ret ,here + dfs(i.second,1)) ;
return ret ;
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;++i){
scanf("%s",str);
m = strlen(str) ;
reverse(str,str+m);
insert_str();
}
memset(mem,-1,sizeof mem);
printf("%d",dfs(0,0));
return 0;
}
Compilation message
rima.cpp: In function 'void insert_str()':
rima.cpp:19:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j<to[cur].size() && to[cur][j].first!=cc) ++j ;
~^~~~~~~~~~~~~~~
rima.cpp:20:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j==to[cur].size()) to[cur].push_back({cc ,++sz}) ;
~^~~~~~~~~~~~~~~~
rima.cpp: In function 'int main()':
rima.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
rima.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",str);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
94328 KB |
Output is correct |
2 |
Correct |
61 ms |
94252 KB |
Output is correct |
3 |
Correct |
59 ms |
94332 KB |
Output is correct |
4 |
Incorrect |
416 ms |
108004 KB |
Output isn't correct |
5 |
Correct |
86 ms |
94456 KB |
Output is correct |
6 |
Incorrect |
106 ms |
122872 KB |
Output isn't correct |
7 |
Incorrect |
100 ms |
122744 KB |
Output isn't correct |
8 |
Incorrect |
98 ms |
122744 KB |
Output isn't correct |
9 |
Incorrect |
130 ms |
123000 KB |
Output isn't correct |
10 |
Incorrect |
103 ms |
122744 KB |
Output isn't correct |