Submission #503081

#TimeUsernameProblemLanguageResultExecution timeMemory
503081tabrType Printer (IOI08_printer)C++17
100 / 100
249 ms5580 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<string> s(n); string t; for (int i = 0; i < n; i++) { cin >> s[i]; if (t.size() < s[i].size()) { t = s[i]; } } vector<vector<int>> a(t.size(), vector<int>(26)); for (int i = 0; i < (int) t.size(); i++) { iota(a[i].begin(), a[i].end(), 0); a[i][t[i] - 'a'] = 100; } sort(s.begin(), s.end(), [&](string xx, string yy) { vector<int> x; for (int i = 0; i < (int) xx.size(); i++) { x.emplace_back(a[i][xx[i] - 'a']); } vector<int> y; for (int i = 0; i < (int) yy.size(); i++) { y.emplace_back(a[i][yy[i] - 'a']); } return x < y; }); string ans; t = ""; for (int i = 0; i < n; i++) { while (!t.empty() && s[i].find(t) != 0) { ans.push_back('-'); t.pop_back(); } while (s[i] != t) { ans.push_back(s[i][t.size()]); t.push_back(s[i][t.size()]); } ans.push_back('P'); } cout << ans.size() << '\n'; for (char c : ans) { cout << c << '\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...