Submission #383794

#TimeUsernameProblemLanguageResultExecution timeMemory
383794penguinhackerType Printer (IOI08_printer)C++14
100 / 100
126 ms48676 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array int n, m, c[500001][26]; bool l[500001]; string ans, b; void dfs(int u = 0) { if (l[u]) ans.push_back('P'); 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']; } l[u] = 1; } 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']; if (l[u]) 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...