# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701210 | 2023-02-20T14:37:08 Z | Do_you_copy | Rima (COCI17_rima) | C++17 | 346 ms | 207532 KB |
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define faster ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; using ll = long long; using pii = pair <int, int>; const int maxN = 3e6 + 10; const int inf = 0x3f3f3f3f; int n; string s[maxN]; struct TNode{ int a[26]; bool ok; TNode(){ memset(a, 0, sizeof(a)); ok = 0; } }; vector <TNode> S(1); int dp[maxN]; void add(int id, int cur, int pos){ if (pos == signed(s[cur].length())){ S[id].ok = 1; return; } if (!S[id].a[s[cur][pos] - 'a']){ S[id].a[s[cur][pos]- 'a'] = S.size(); S.pb(TNode()); } add(S[id].a[s[cur][pos] - 'a'], cur, pos + 1); } int ans = 0; void dfs(int u){ pii maxx = {0, 0}; for (int i = 0; i < 26; ++i){ if (S[u].a[i]){ dfs(S[u].a[i]); if (maxx.fi < dp[S[u].a[i]]){ swap(maxx.fi, maxx.se); maxx.fi = dp[S[u].a[i]]; } else{ maxx.se = max(maxx.se, dp[S[u].a[i]]); } } } int tem = maxx.fi + maxx.se + S[u].ok; ans = max(ans, tem); if (S[u].ok) dp[u] = tem; } void Init(){ cin >> n; for (int i = 1; i <= n; ++i){ cin >> s[i]; reverse(s[i].begin(), s[i].end()); add(0, i, 0); } dfs(0); cout << ans; } #define taskname "test" signed main(){ if (fopen(taskname ".inp", "r")){ freopen(taskname ".inp", "r", stdin); freopen(taskname ".out", "w", stdout); } int tt = 1; //cin >> tt; while (tt--){ Init(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 94224 KB | Output is correct |
2 | Incorrect | 41 ms | 94276 KB | Output isn't correct |
3 | Incorrect | 41 ms | 94196 KB | Output isn't correct |
4 | Incorrect | 346 ms | 207532 KB | Output isn't correct |
5 | Correct | 111 ms | 101656 KB | Output is correct |
6 | Incorrect | 129 ms | 151244 KB | Output isn't correct |
7 | Incorrect | 113 ms | 150828 KB | Output isn't correct |
8 | Incorrect | 115 ms | 150572 KB | Output isn't correct |
9 | Incorrect | 179 ms | 158488 KB | Output isn't correct |
10 | Incorrect | 109 ms | 150688 KB | Output isn't correct |