# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
285726 |
2020-08-29T13:57:08 Z |
HynDuf |
Rima (COCI17_rima) |
C++14 |
|
379 ms |
134904 KB |
#include <bits/stdc++.h>
#define task "R"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 5e5 + 2;
int n, ans;
struct Node
{
Node *child[26];
int ans;
bool leaf;
Node() {ans = 0; leaf = 0; rep(i, 0, 25) child[i] = nullptr;}
};
Node *root;
void add(const string &t)
{
Node *u = root;
rep(i, 0, SZ(t) - 1)
{
if (u->child[t[i] - 'a'] == nullptr) u->child[t[i] - 'a'] = new Node();
u = u->child[t[i] - 'a'];
}
u->leaf = 1;
}
void dfs(Node *u, Node *p)
{
int cnt = 0;
rep(i, 0, 25) cnt += (p->child[i] != nullptr && (p->child[i])->leaf);
if (u->leaf) u->ans = cnt;
if (p->leaf) u->ans += p->ans;
ans = max(ans, u->ans);
rep(i, 0, 25) if (u->child[i] != nullptr) dfs(u->child[i], u);
}
int main()
{
#ifdef HynDuf
freopen(task".in", "r", stdin);
//freopen(task".out", "w", stdout);
#else
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
cin >> n;
root = new Node();
rep(i, 1, n)
{
string s;
cin >> s;
reverse(all(s));
add(s);
}
rep(i, 0, 25) if (root->child[i] != nullptr) dfs(root->child[i], root);
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
379 ms |
134904 KB |
Output isn't correct |
5 |
Correct |
15 ms |
896 KB |
Output is correct |
6 |
Incorrect |
92 ms |
76116 KB |
Output isn't correct |
7 |
Incorrect |
92 ms |
76008 KB |
Output isn't correct |
8 |
Incorrect |
90 ms |
75808 KB |
Output isn't correct |
9 |
Incorrect |
127 ms |
79136 KB |
Output isn't correct |
10 |
Incorrect |
89 ms |
75844 KB |
Output isn't correct |