답안 #229920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229920 2020-05-07T06:39:27 Z mohamedsobhi777 Rima (COCI17_rima) C++14
42 / 140
1000 ms 143224 KB
#include<bits/stdc++.h>

using namespace std ; 


const int N = 5e5 + 7 ; 

int n  ; 
string ss[N] ; 

struct trie{
    int nxt[N][27] ; 
    int cnt[N] ; 
    int t = 1 ; 
    void add(string &add_ ){
        int cur = 1 ; 
        int sz = add_.size() ; 
        for(int i = 0 ;i < sz ;i++ ){
            int c = add_[i] - 'a' ; 
            if(!nxt[cur][c])nxt[cur][c] = ++t ;
            cur = nxt[cur][c] ;
        }
        cnt[cur] ++ ; 
    }

    int solve(int i , bool flag){
        if(flag && !cnt[i]) return -1e8 ; 
        int ret = 0 ; 
        int kids = 0 ; 
        
        for(int j = 0 ;j < 26 ;j ++){
            kids +=cnt[nxt[i][j]] ; 
        }

        for(int j = 0 ;j < 26 ; j++){
            if(nxt[i][j]){
                ret = max(ret ,  solve(nxt[i][j] , flag )  ) ; 
                ret = max(ret , solve(nxt[i][j] , 1) + kids ) ; 
            }
        }
        return ret ; 
    }

} tr; 

int main(){
    ios_base::sync_with_stdio(0) ; 
    cin.tie(0) ; 
    //freopen("in.in" , "r" , stdin) ; 
    cin>>n ; 
    for(int i = 0 ; i < n ;i++){
        string x ; 
        cin>>x ; 
        reverse( x .begin() , x.end()) ; 
        tr.add(x) ; 
    }
    cout<< tr.solve(1 , 0) ;  
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 16128 KB Output is correct
2 Correct 15 ms 16128 KB Output is correct
3 Correct 13 ms 16000 KB Output is correct
4 Runtime error 204 ms 143224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Execution timed out 1087 ms 17016 KB Time limit exceeded
6 Execution timed out 1099 ms 118744 KB Time limit exceeded
7 Execution timed out 1096 ms 48420 KB Time limit exceeded
8 Execution timed out 1101 ms 48472 KB Time limit exceeded
9 Execution timed out 1101 ms 49580 KB Time limit exceeded
10 Execution timed out 1098 ms 118732 KB Time limit exceeded