# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1010644 | Muaath_5 | Type Printer (IOI08_printer) | C++17 | 64 ms | 38740 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
const int N = 5001, MOD = 1e9+7;
using namespace std;
struct trie {
char ch = 0;
bool end = false;
trie* chrs[26];
int mxdep = 0;
};
int n;
trie* root = new trie();
void add(string& x) {
trie* cur = root;
for (int i = 0; i < x.size(); i++) {
if (!cur->chrs[x[i] - 'a'])
cur->chrs[x[i] - 'a'] = new trie();
cur = cur->chrs[x[i] - 'a'];
cur->ch = x[i];
}
cur->end = true;
}
void dfs(trie* cur) {
cur->mxdep = 1;
for (trie* c : cur->chrs) {
if (c) {
dfs(c);
cur->mxdep = max(cur->mxdep, c->mxdep+1);
}
}
}
int cnt = 0;
void dfs2(trie* cur) {
if (cur == nullptr) return;
sort(cur->chrs, cur->chrs+26, [](trie* x, trie* y){
return (x ? x->mxdep : 0) < (y ? y->mxdep : 0);
});
if (cur->ch != 0)
cout << cur->ch << '\n';
if (cur->end) {
cout << "P\n";
cnt++;
if (cnt == n) exit(0);
}
for (int i = 0; i < 26; i++) {
if (cur->chrs[i]) {
dfs2(cur->chrs[i]);
}
}
cout << "-\n";
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
string w;
cin >> w;
add(w);
}
dfs(root);
dfs2(root);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |