# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
475378 | cpp219 | Rima (COCI17_rima) | C++14 | 423 ms | 135692 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
typedef pair<ld,ll> LD;
const ll N = 5e5 + 9;
const ll mod = 1e9 + 7;
const ll base = 31;
ll n,kq;
string s;
struct Trie{
Trie *child[26]; ll have = 0,sz = 0;
void Add(string &s,ll now){
sz += (now == s.size() - 1 && now);
if (now == s.size()){
have = 1; return;
}
ll c = s[now] - 'a';
if (!child[c]) child[c] = new Trie();
child[c] -> Add(s,now + 1);
}
ll GetMax(ll dep){
priority_queue<ll,vector<ll>,greater<ll>> pq; pq.push(0); pq.push(0);
for (ll i = 0;i < 26;i++) if (child[i])
pq.push(child[i] -> GetMax(dep + 1));
while(pq.size() > 2) pq.pop();
ll ans = pq.top(),got = (have > 0 || dep == 0); pq.pop();
//if (sz == 1) debug(got);
kq = max(kq,(ans + pq.top() + sz + got - (ans > 0) - (pq.top() > 0)));
kq = max(kq,(pq.top() + sz + got - (pq.top() > 0)));
if (kq == 5) debug(pq.top());
return (pq.top() + sz + 1 - (pq.top() > 0))*got;
}
}Tree;
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin>>n;
for (ll i = 1;i <= n;i++){
cin>>s; reverse(s.begin(),s.end());
Tree.Add(s,0);
}
Tree.GetMax(0);
cout<<kq;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |