#include<bits/stdc++.h>
using namespace std;
#ifdef ONPC
#include"debug.h"
#else
#define debug(...) 42
#endif
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 15;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
bool good_set = 1;
int trie[MAXN][26];
int Data[MAXN];
int dep[MAXN];
int node_cnt = 1;
void insert(string s){
int node = 1;
for (char c : s){
if (!trie[node][c - 'a']){
trie[node][c - 'a'] = ++node_cnt;
}
node = trie[node][c - 'a'];
}
Data[node]++;
return;
}
int cnt = 0;
int n;
void calc_dep(int node){
int mx = 0;
for (int i = 0; i < 26; i++){
if (trie[node][i]){
calc_dep(trie[node][i]);
ckmax(mx, dep[trie[node][i]]);
}
}
dep[node] = mx + 1;
}
void solve(int node){
if (Data[node]){
cout << 'P' << endl;
cnt++;
if (cnt == n) exit(0);
}
vector<int> children;
for (int i = 0; i < 26; i++){
if (trie[node][i]){
children.pb(i);
}
}
sort(all(children), [&](int l, int r){ return dep[trie[node][l]] < dep[trie[node][r]]; });
for (int child : children){
cout << char(child + 'a') << endl;
solve(trie[node][child]);
cout << '-' << endl;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++){
string s;
cin >> s;
insert(s);
}
calc_dep(1);
solve(1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Expected integer, but "t" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Expected integer, but "n" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Expected integer, but "h" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Expected integer, but "q" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2512 KB |
Expected integer, but "w" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3160 KB |
Expected integer, but "v" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
5212 KB |
Expected integer, but "n" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
11352 KB |
Expected integer, but "n" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
23892 KB |
Expected integer, but "n" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
20056 KB |
Expected integer, but "n" found |
2 |
Halted |
0 ms |
0 KB |
- |