Submission #237286

#TimeUsernameProblemLanguageResultExecution timeMemory
237286nikatamlianiType Printer (IOI08_printer)C++14
100 / 100
114 ms52016 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100, M = 25005; int codes[N][26], cntEnd[N * 26]; bool marked[N * 26]; int n, tries, maxLength, maxString; string ans, s[M]; void add(string &s, bool mark){ int code = 0; for(int i = 0; i < (int)s.size(); ++i){ int c = s[i] - 'a'; if(!codes[code][c]){ codes[code][c] = ++tries; } code = codes[code][c]; marked[code] = mark; } cntEnd[code] += !mark; } void findMinTime(int code){ for(int i = 0; i < cntEnd[code]; ++i)ans += 'P'; int last = -1; for(int i = 0; i < 26; ++i){ if(!codes[code][i])continue; if(marked[codes[code][i]]){ last = i; }else{ ans += char(i + 'a'); findMinTime(codes[code][i]); ans += '-'; } } if(~last){ ans += char(last + 'a'); findMinTime(codes[code][last]); } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; ++i){ cin >> s[i]; add(s[i], 0); if(maxLength < (int)s[i].size()){ maxLength = (int)s[i].size(); maxString = i; } } add(s[maxString], 1); findMinTime(0); cout << (int)ans.size() << endl; for(int i = 0; i < (int)ans.size(); ++i){ cout << ans[i] << '\n'; } }
#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...