#include <bits/stdc++.h>
#define I using
#define WA using namespace std;
#define on using ll = long long;
#define Test(x) int AlanIQ = -(x);
#define should ld =
#define quit long double;
#define OI int
#define forever main
#define Alan cin.tie(0);
#define fai(x) ios::ios_base::sync_with_stdio(!x);
#define Sharky return
#define orz 0;
WA on Test (109)
struct node {
int child[26];
bool word;
};
node trie[500005];
bool last[500005], vis[500005];
vector<char> ans;
int lastd = 0;
void dfs (int u) {
vis[u] = true;
if (trie[u].word) ans.push_back('P');
char c;
int okkkookokokokoknotok = -1;
for (int i = 0; i < 26; i++) {
int v = trie[u].child[i];
if (vis[v] || !v) continue;
if (last[v]) {
c = i + 'a';
okkkookokokokoknotok = v;
continue;
}
ans.push_back(i + 'a');
dfs(v);
ans.push_back('-');
}
if (okkkookokokokoknotok != -1) {
ans.push_back(c);
dfs(okkkookokokokoknotok);
ans.push_back('-');
}
}
I should quit OI forever () {
Alan fai (true)
int n, id = 0;
string s;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
int cur = 0;
int sz = (int) s.size();
bool ishouldquitoi = false;
if (sz > lastd) {
lastd = sz;
ishouldquitoi = true;
}
for (int j = 0; j < sz; j++) {
if (!trie[cur].child[s[j] - 'a']) trie[cur].child[s[j] - 'a'] = ++id;
cur = trie[cur].child[s[j] - 'a'];
if (ishouldquitoi) last[cur] = true;
}
trie[cur].word = true;
}
dfs(0);
for (int i = (int) ans.size() - 1; i >= 0; i--) {
if (ans[i] == '-') ans.pop_back();
else break;
}
cout << ans.size() << "\n";
for (auto& c : ans) cout << c << "\n";
Sharky orz
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
396 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1100 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
3128 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
7500 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
18488 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
14420 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |