# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994048 | 2024-06-07T05:04:34 Z | vjudge1 | Rima (COCI17_rima) | C++17 | 282 ms | 134832 KB |
#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 = 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) { dp += ch[i]->dp; } } ans = max(ans, dp); 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; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Incorrect | 282 ms | 134832 KB | Output isn't correct |
5 | Correct | 39 ms | 860 KB | Output is correct |
6 | Incorrect | 71 ms | 75980 KB | Output isn't correct |
7 | Incorrect | 61 ms | 75980 KB | Output isn't correct |
8 | Incorrect | 61 ms | 75720 KB | Output isn't correct |
9 | Incorrect | 112 ms | 78864 KB | Output isn't correct |
10 | Incorrect | 63 ms | 75720 KB | Output isn't correct |