| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 931366 | rahidilbayramli | Type Printer (IOI08_printer) | C++17 | 50 ms | 56300 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>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define pb push_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 1e5+5;
ll triee[sz][26], value[sz], subtree[sz], next_node = 1;
map<ll, char>mp;
vector<char>res;
void add(string& s, ll id)
{
ll node = 0;
for(ll idx = 0; idx < s.size(); idx++)
{
ll ch = s[idx] - 'a';
if(!triee[node][ch]){
triee[node][ch] = next_node;
mp[next_node] = s[idx];
next_node++;
}
node = triee[node][ch];
}
value[node] = 1;
}
void dfs1(ll node = 0)
{
subtree[node] = 1;
for(ll i = 0; i < 26; i++)
{
if(triee[node][i]){
dfs1(triee[node][i]);
subtree[node] += subtree[triee[node][i]];
}
}
}
void dfs(ll node = 0)
{
if(node)
res.pb(mp[node]);
if(value[node])
res.pb('P');
vector<pll>vv;
for(ll i = 0; i < 26; i++)
{
if(triee[node][i])
vv.pb({subtree[triee[node][i]], triee[node][i]});
}
sort(all(vv));
for(ll i = 0; i < vv.size(); i++)
dfs(vv[i].s);
res.pb('-');
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tests = 1;
//cin >> tests;
while(tests--)
{
ll n, i;
cin >> n;
for(i = 1; i <= n; i++)
{
string s;
cin >> s;
add(s, i);
}
dfs1();
dfs();
while(res.back() == '-')
res.pop_back();
cout << res.size() << "\n";
for(auto u : res)
cout << u << "\n";
}
}
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... | ||||
