답안 #114077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114077 2019-05-29T22:45:16 Z zoooma13 Rima (COCI17_rima) C++14
56 / 140
622 ms 81144 KB
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 500005

int n;
string s[MAX_N];

int root ,nn;
int tr[27][10*MAX_N];
void add(int&p ,string&s ,int i=0){
    if(!p) p = ++nn;
    if(i == s.size()){
        tr[26][p]++;
        return;
    }
    add(tr[s[i]-'a'][p] ,s ,i+1);
}
int max_suf = 0;
int dfs(int&p){
    int ch ,mx_ch = 0 ,all_en = 0;
    for(int c=0; c<26; c++) if(tr[c][p]){
        ch = dfs(tr[c][p]);
        if(tr[26][tr[c][p]])
            mx_ch = max(mx_ch ,ch);
        all_en +=  tr[26][tr[c][p]];
    }

    max_suf = max(max_suf ,mx_ch+all_en);
    return (all_en ? mx_ch+all_en : 0);
}

int main()
{
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> s[i];
        reverse(s[i].begin() ,s[i].end());
        add(root ,s[i]);
    }
    dfs(root);
    cout << max_suf << endl;
}

Compilation message

rima.cpp: In function 'void add(int&, std::__cxx11::string&, int)':
rima.cpp:13:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(i == s.size()){
        ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16220 KB Output is correct
2 Correct 14 ms 16256 KB Output is correct
3 Correct 15 ms 16256 KB Output is correct
4 Incorrect 622 ms 81144 KB Output isn't correct
5 Correct 110 ms 20468 KB Output is correct
6 Incorrect 114 ms 61924 KB Output isn't correct
7 Incorrect 108 ms 61724 KB Output isn't correct
8 Incorrect 105 ms 61576 KB Output isn't correct
9 Incorrect 205 ms 66788 KB Output isn't correct
10 Incorrect 101 ms 61592 KB Output isn't correct