Submission #244904

#TimeUsernameProblemLanguageResultExecution timeMemory
244904NONAMERima (COCI17_rima)C++14
56 / 140
380 ms150496 KiB
#include <bits/stdc++.h> #define dbg(x) cerr << #x << " = " << x << "\n" #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie() using namespace std; using ll = long long; const int N = 5e5 + 10; int n, ans = 1; string s[N]; struct trie { trie *nxt[26]; int cnt, res; trie() { for (int i = 0; i < 26; ++i) nxt[i] = 0; cnt = 0; res = 0; } void add(string &t, int p = 0) { if (p == int(t.size())) { ++cnt; return; } int j = t[p] - 'a'; if (nxt[j] == 0) nxt[j] = new trie(); nxt[j] -> add(t, p + 1); } void f() { for (int i = 0; i < 26; ++i) if (nxt[i] != 0) nxt[i] -> f(); for (int i = 0; i < 26; ++i) if (nxt[i] != 0) res += (nxt[i] -> res); if (!cnt) res = 0; else ++res; ans = max(ans, res); } } tr; int main() { fast_io; cin >> n; for (int i = 0; i < n; ++i) { cin >> s[i]; reverse(s[i].begin(), s[i].end()); tr.add(s[i]); } tr.f(); cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...