# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
229554 | Uzumaki_Naturoo | Rima (COCI17_rima) | C++14 | 137 ms | 262148 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// 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 ;
char str[N] ;
int to[26][N] ,sz ;
bool en[N] ;
void insert_str(){
int cur = 0 ;
for(int i=0;i<m;++i){
int cc = str[i] - 'a' ;
if(to[cc][cur]==-1) to[cc][cur] = ++sz ;
cur = to[cc][cur] ;
}
en[cur] = 1 ;
}
int mem[N][2] ;
int dfs(int cur,bool is){
int&ret = mem[cur][is];
if(~ret) return ret;
ret = 0 ;
if(!is){
for(int i=0;i<26;++i) if(to[i][cur]!=-1) ret = max(ret ,dfs(to[i][cur],0)) ;
}
int here = 0 ;
for(int i=0;i<26;++i) if(to[i][cur]!=-1) here += en[to[i][cur]] ;
if(!here) return ret ;
ret = max(ret,here) ;
for(int i=0;i<26;++i) if(to[i][cur]!=-1 && en[to[i][cur]]) ret = max(ret ,here + dfs(to[i][cur],1)) ;
return ret ;
}
int main(){
memset(to,-1,sizeof to);
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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |