# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
114078 | zoooma13 | Rima (COCI17_rima) | C++14 | 576 ms | 65392 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 500005
#define MAX_S 3000006
int n;
string s;
int root ,nn;
int tr[27][MAX_S];
void add(int&p ,int i=0){
if(!p) p = ++nn;
if(i == s.size()){
tr[26][p]++;
return;
}
add(tr[s[i]-'a'][p] ,i+1);
}
int max_suf = 0;
int dfs(int&p){
int ch ,frst_mx_ch = 0 ,scnd_mx_ch = 0 ,all_en = 0;
for(int c=0; c<26; c++) if(tr[c][p])
{
ch = dfs(tr[c][p]);
all_en += tr[26][tr[c][p]];
if(tr[26][tr[c][p]])
{
if(frst_mx_ch < ch){
scnd_mx_ch = frst_mx_ch;
frst_mx_ch = ch;
}
else if(scnd_mx_ch < ch){
scnd_mx_ch = ch;
}
}
}
max_suf = max(max_suf ,frst_mx_ch+scnd_mx_ch+all_en+tr[26][p]);
return frst_mx_ch+all_en;
}
int main()
{
cin >> n;
for(int i=0; i<n; i++){
cin >> s; reverse(s.begin() ,s.end());
add(root);
}
for(int c=0; c<26; c++)
if(tr[c][root])
dfs(tr[c][root]);
cout << max_suf << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |