Submission #1108350

#TimeUsernameProblemLanguageResultExecution timeMemory
1108350vjudge1Type Printer (IOI08_printer)C++17
100 / 100
142 ms61444 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define endl "\n" #define F first #define S second #define pb push_back #define eb emplace_back #define rep(i, a, b) for(int i = a; i < b; i++) #define tam(s) (int)s.size() #define all(x) x.begin(), x.end() #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); typedef vector<int> vi; typedef pair<int, char> pic; typedef tuple<int, int, int> tii; const int lim=500001; int t[lim], fim[lim]; int32_t main(){ fastio; int n, k=0, l; string s, ans=""; cin >> n; map<char, int> m[lim]; rep(i, 0, n){ cin >> s; int j=0, p=0; for(char c: s){ auto it = m[j].find(c); if(it == m[j].end()) m[j][c] = ++k, j=k; else j=m[j][c]; t[j] = max(t[j], tam(s)-p); p++; } fim[j]++; } auto dfs=[&] (auto self, int i) -> void { while(fim[i]--){ ans += 'P'; l = tam(ans); } if(m[i].empty()) return; vector<pic> v; for(auto [a, b] : m[i]) v.eb(t[b], a); sort(all(v)); for(auto [a, b] : v){ ans += b; self(self, m[i][b]); ans += '-'; } }; dfs(dfs, 0); cout << l << endl; rep(i, 0, l) cout << ans[i] << endl; return 0; }
#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...