Submission #757772

#TimeUsernameProblemLanguageResultExecution timeMemory
757772taherType Printer (IOI08_printer)C++17
100 / 100
151 ms5600 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<string> v(n); for (int i = 0 ; i < n ; i++) { cin >> v[i]; } sort(v.begin(),v.end(),[&](string a , string b) { int q = (int)a.length(); int s = (int)b.length(); return q < s; }); auto Get = [&](string a , string b) { int cnt = 0; for (int i = 0 ; i < min((int)a.length() , (int)b.length()) ; i++) { if (a[i] != b[i]) break; else cnt++; } return cnt; }; string get = v[n - 1]; sort(v.begin(),v.end(),[&](string a , string b) { int _fa = Get(get , a); int _fb = Get(get , b); if (_fa == _fb) { return a < b; } return _fa < _fb; }); //debug(v); vector<char> ans; int last = -1; for (int i = 0 ; i < n ; i++) { int nxt = -1; bool ok = true; for (int j = 0 ; j < (int)v[i].length() ; j++) { if (j > last) ans.emplace_back(v[i][j]); if (i < n - 1 && j < (int)v[i + 1].length() && v[i][j] == v[i + 1][j] && ok) { nxt = j; } else ok = false; } ans.emplace_back('P'); if (i == n - 1) continue; for (int j = (int)v[i].length() - 1 ; j > nxt ; j--) { ans.emplace_back('-'); } swap(last , nxt); } cout << (int)ans.size() << '\n'; for (int i = 0 ; i < (int)ans.size() ; i++) { cout << ans[i] << '\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...