답안 #229559

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229559 2020-05-05T06:00:09 Z Uzumaki_Naturoo Rima (COCI17_rima) C++14
70 / 140
402 ms 141816 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 ;
vector<pair<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' ;
        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] = 1 ;
}
int mem[N][2] ;
int dfs(int cur,bool is){
    int&ret = mem[cur][is];
    if(~ret) return ret;
    ret = 0 ;
    int here = 0 ;
    for(auto i:to[cur]) here += en[i.second] ;
    if(!is){
        for(auto i:to[cur]) ret = max(ret ,dfs(i.second,0));
        vector<int> v ;
        for(auto i:to[cur]) if(en[i.second]){
            v.push_back(dfs(i.second,1));
            sort(v.rbegin(),v.rend());
            if(v.size()>2) v.pop_back();
        }
        int s = 0 ;
        for(int i:v) s += i ;
        return ret = max(ret ,here + s) ; ;
    }
    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:20:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j<to[cur].size() && to[cur][j].first!=cc) ++j ;
               ~^~~~~~~~~~~~~~~
rima.cpp:21: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:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
rima.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",str);
         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 94328 KB Output is correct
2 Correct 56 ms 94200 KB Output is correct
3 Correct 57 ms 94328 KB Output is correct
4 Correct 402 ms 106336 KB Output is correct
5 Correct 83 ms 94712 KB Output is correct
6 Incorrect 105 ms 141560 KB Output isn't correct
7 Incorrect 106 ms 141560 KB Output isn't correct
8 Incorrect 106 ms 141688 KB Output isn't correct
9 Incorrect 136 ms 141816 KB Output isn't correct
10 Incorrect 104 ms 141560 KB Output isn't correct