Submission #383783

#TimeUsernameProblemLanguageResultExecution timeMemory
383783penguinhackerType Printer (IOI08_printer)C++14
20 / 100
52 ms18568 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array int n, m, c[500001][26], cnt[500001]; string ans, b; void dfs(int u = 0) { while(cnt[u]) { ans.push_back('P'); --cnt[u]; } for (int i = 0; i < 26; ++i) if (c[u][i]) { ans.push_back('a' + i); dfs(c[u][i]); ans.push_back('-'); } } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; m = 1; for (int i = 0; i < n; ++i) { string s; cin >> s; if (s.size() > b.size()) b = s; int u = 0; for (char d : s) { if (!c[u][d - 'a']) c[u][d - 'a'] = m++; u = c[u][d - 'a']; } ++cnt[u]; } int u = 0; for (char d : b) { for (int i = 0; i < 26; ++i) if (c[u][i] && i != d - 'a') { ans.push_back('a' + i); dfs(c[u][i]); ans.push_back('-'); } ans.push_back(d); u = c[u][d - 'a']; } ans += 'P'; cout << ans.size() << "\n"; for (char d : ans) cout << d << "\n"; 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...