| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 735588 | vjudge1 | Rima (COCI17_rima) | C++17 | 2 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct Node {
Node* childs[26];
int dp;
bool isleaf = false;
Node() {
dp = 0;
for (auto& child : childs) child = NULL;
}
~Node() {
for (auto& child : childs) delete child;
}
};
struct Trie {
Node* root;
int max_dp = 0;
Trie() { root = new Node(); }
~Trie() { delete root; }
void insert(string s) {
Node* node = root;
for (const char& c : s) {
if (node->childs[c - 'a'] == NULL) node->childs[c - 'a'] = new Node();
node = node->childs[c - 'a'];
}
node->isleaf = true;
}
int dfs(Node* node) {
int best = 0, cntLeafs = 0;
for(char c = 'a' ; c <= 'z' ; ++c) {
if(node->childs[c - 'a'] != NULL) {
best = max(best, dfs(node->childs[c - 'a']) - 1);
cntLeafs += node->childs[c - 'a']->isleaf;
}
}
if(node->isleaf)
node->dp = cntLeafs + best + 1;
max_dp = max(max_dp, node->dp);
max_dp = max(max_dp, cntLeafs + best);
return node->dp;
}
};
void solve() {
int n;
cin >> n;
Trie t;
for(int i = 0 ; i < n ; ++i) {
string s;
cin >> s;
reverse(s.begin(), s.end());
t.insert(s);
}
int tmp = t.dfs(t.root);
cout << t.max_dp << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#else
#endif
int tc = 1;
// cin >> tc;
while(tc--) {
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
