# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
994053 | vjudge1 | Rima (COCI17_rima) | C++17 | 286 ms | 134852 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct node
{
node * ch[26] = {NULL};
bool e = false;
int dp;
int dfs()
{
//cerr << "I'm" << endl;
int ans = 0;
int mx[2] = {0};
dp = e;
for(int i = 0; i < 26; i++)
{
if(ch[i] == NULL) continue;
// cerr << "---> " << char(i + 'a') << endl;
ans = max(ans, ch[i]->dfs());
// cerr << ch[i] -> dp << endl;
// cerr << "<---" << char(i + 'a') << endl;
if(ch[i] -> e)
{
mx[1] = max(mx[1], ch[i]->dp - 1);
if(mx[0] < mx[1]) swap(mx[0], mx[1]);
dp++;
}
}
dp += mx[0];
ans = max(ans, dp + mx[1]);
return ans;
}
};
struct Trie
{
node * root;
Trie() {
root = new node();
}
void insert(string &s)
{
node *cur = root;
for(int i = s.size() - 1; i >= 0; i--)
{
int idx = s[i] - 'a';
if(cur -> ch[idx] == NULL)
cur -> ch[idx] = new node();
cur = cur -> ch[idx];
}
cur -> e = true;
}
int compute()
{
return root->dfs();
}
} T;
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i ++)
{
string s;
cin >> s;
T.insert(s);
}
cout << T.compute() << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |