# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
960542 |
2024-04-10T15:34:13 Z |
LM1 |
Rima (COCI17_rima) |
C++14 |
|
343 ms |
154040 KB |
#include <bits/stdc++.h>
using namespace std;
const int N=5e5+5,M=3e6+5;
int t,n,dp[M],fix[M][26],ans=1,cn,cnt[M];
vector<int>v[M];
string s;
void add(string s){
int cur=0;
for(int i=0;i<(int)s.size();i++){
int c=s[i]-'a';
if(!fix[cur][c]){
cn++;
fix[cur][c]=cn;
v[cur].push_back(fix[cur][c]);
}
cur=fix[cur][c];
}
cnt[cur]++;
}
void dfs(int st,int p){
if(v[st].size()==0 and st>0){
dp[st]=1;
return;
}
int mx=0;
vector<int>v1;
for (int i:v[st]){
if (i==p)continue;
dfs(i,st);
mx=max(mx,dp[i]);
if(dp[i])v1.push_back(dp[i]);
}
sort(v1.begin(),v1.end());
if(v1.size()>=2)ans=max(ans,v1.back()+v1[v1.size()-2]+(int)v1.size()-2);
ans=max(ans,mx+(int)v1.size()-(!cnt[st]));
if(cnt[st])dp[st]=mx+1+v1.size()-min((int)v1.size(), 1);
else dp[st]=0;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>s;
reverse(s.begin(),s.end());
add(s);
}
dfs(0,0);
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
74460 KB |
Output is correct |
2 |
Correct |
18 ms |
74432 KB |
Output is correct |
3 |
Correct |
18 ms |
74440 KB |
Output is correct |
4 |
Correct |
343 ms |
152912 KB |
Output is correct |
5 |
Correct |
69 ms |
77896 KB |
Output is correct |
6 |
Incorrect |
74 ms |
150420 KB |
Output isn't correct |
7 |
Incorrect |
84 ms |
150360 KB |
Output isn't correct |
8 |
Incorrect |
72 ms |
150256 KB |
Output isn't correct |
9 |
Incorrect |
143 ms |
154040 KB |
Output isn't correct |
10 |
Incorrect |
73 ms |
150208 KB |
Output isn't correct |