Submission #229555

# Submission time Handle Problem Language Result Execution time Memory
229555 2020-05-05T05:12:52 Z Uzumaki_Naturoo Rima (COCI17_rima) C++14
56 / 140
835 ms 262148 KB
/// 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 ;
map<int,int> to[N] ;
char str[N] ;
bool en[N] ;
void insert_str(){
    int cur = 0 ;
    for(int i=0;i<m;++i){
        int cc = str[i] - 'a' ;
        if(!to[cur][cc]) to[cur][cc] = ++sz ;
        cur = to[cur][cc] ;
    }
    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[cur][i]) ret = max(ret ,dfs(to[cur][i],0)) ;
    }

    int here = 0 ;
    for(int i=0;i<26;++i) if(to[cur][i]) here += en[to[cur][i]] ;
    if(!here) return ret ;

    ret = max(ret,here) ;
    for(int i=0;i<26;++i) if(to[cur][i] && en[to[cur][i]]) ret = max(ret ,here + dfs(to[cur][i],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 'int main()':
rima.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
rima.cpp:44: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 102 ms 165112 KB Output is correct
2 Correct 96 ms 165072 KB Output is correct
3 Correct 96 ms 165112 KB Output is correct
4 Runtime error 835 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Correct 144 ms 168056 KB Output is correct
6 Runtime error 247 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 243 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 240 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 308 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 235 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)