Submission #965367

#TimeUsernameProblemLanguageResultExecution timeMemory
965367dostsType Printer (IOI08_printer)C++17
100 / 100
177 ms96976 KiB
//Dost SEFEROĞLU #pragma GCC optimize("O3,unroll-loops,Ofast") #include <bits/stdc++.h> using namespace std; //#define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define vi vector<int> const int N = 5e5+100,inf = 1e9,MOD = 1e9+7; string S; int origsize; vector<char> instructions; struct Trie { unordered_map<char,Trie*> children; int ultimo = 0,star = 0,deepshit = 0; void insert(string* ss) { ultimo++; if (ss->empty()) { star++; deepshit = max(deepshit,origsize); return; } char cc = ss->back(); ss->pop_back(); if (!children.count(cc)) children[cc] = new Trie; children[cc]->insert(ss); deepshit = max(deepshit,children[cc]->deepshit); } void dfs() { while (star) { star--; instructions.push_back('P'); } vector<pair<int,char>> childs; for (auto it : children) childs.push_back({it.ss->deepshit,it.ff}); sort(childs.begin(),childs.end()); for (auto it : childs) { instructions.push_back(it.ss); children[it.ss]->dfs(); } instructions.push_back('-'); } } *root = new Trie; void solve() { int n; cin >> n; for (int i=1;i<=n;i++) { cin >> S; origsize = S.size(); reverse(S.begin(),S.end()); root->insert(&S); } root->dfs(); while (instructions.back() == '-') instructions.pop_back(); cout << instructions.size() << '\n'; for (auto it : instructions) cout << it << '\n'; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Dodi freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while (t --> 0) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...