# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1004918 |
2024-06-22T04:06:00 Z |
vjudge1 |
Rima (COCI17_rima) |
C++17 |
|
224 ms |
162668 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*
Phu Trong from Nguyen Tat Thanh High School for gifted student
*/
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
int n;
#define All(x...) (x).begin(), (x).end()
struct Node{
Node* child[26];
int last, dp;
Node(){
REP(i, 26) child[i] = nullptr;
last = 0, dp = 0;
}
};
int numNode = 0;
Node *root = new Node();
void Add(string &s){
Node *p = root;
for (char c : s){
int nxt = (c - 'a');
if (p -> child[nxt] == nullptr){
p -> child[nxt] = new Node();
}
p = p -> child[nxt];
}
p -> last = 1;
}
int ans = 0;
void dfs(Node *p){
REP(c, 26) if(p -> child[c] != nullptr){
dfs(p -> child[c]);
}
int cnt = 0;
int mx_first = 0, mx_second = 0;
REP(c, 26){
if (p -> child[c] != nullptr){
if (p -> child[c] -> last){
++cnt;
if (p -> child[c] -> dp > mx_first) swap(mx_first, mx_second), mx_first = p -> child[c] -> dp;
else maximize(mx_second, p -> child[c] -> dp);
}
}
}
p -> dp = mx_first + cnt;
maximize(ans, p -> dp + mx_second + p -> last);
}
void process(void){
cin >> n;
vector<string> s(n);
for (string&i : s) cin >> i;
for (string&i : s) reverse(All(i)), Add(i);
dfs(root);
cout << ans;
}
signed main(){
#define name "Whisper"
cin.tie(nullptr) -> sync_with_stdio(false);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
process();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
224 ms |
162668 KB |
Output is correct |
5 |
Correct |
11 ms |
6896 KB |
Output is correct |
6 |
Correct |
57 ms |
86812 KB |
Output is correct |
7 |
Correct |
60 ms |
86552 KB |
Output is correct |
8 |
Correct |
57 ms |
86188 KB |
Output is correct |
9 |
Correct |
94 ms |
95128 KB |
Output is correct |
10 |
Correct |
61 ms |
86160 KB |
Output is correct |