| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 99170 | dalgerok | Rima (COCI17_rima) | C++17 | 586 ms | 67868 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, M = 3e6 + 5;
int n, cnt[M], sz, dp[M], ans;
int bor[26][M];
string s;
inline void Add(string &s){
int v = 0;
for(auto it : s){
if(!bor[it][v]){
bor[it][v] = ++sz;
}
v = bor[it][v];
}
cnt[v] += 1;
}
void dfs(int v){
int mx1 = 0, mx2 = 0, sum = 0;
for(int i = 0; i < 26; i++){
int to = bor[i][v];
if(!to){
continue;
}
dfs(to);
sum += cnt[to];
if(dp[to] > mx1){
mx2 = mx1;
mx1 = dp[to];
}
else if(dp[to] > mx2){
mx2 = dp[to];
}
dp[v] = max(dp[v], dp[to]);
}
if(cnt[v]){
dp[v] += 1 + max(0, sum - 1);
}
else{
dp[v] = 0;
}
///cout << v << " " << dp[v] << " " << cnt[v] << "\n";
ans = max(ans, mx1 + mx2 + cnt[v] + max(0, sum - 2));
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> s;
reverse(s.begin(), s.end());
for(auto &it : s){
it -= 'a';
}
Add(s);
}
dfs(0);
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
