# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1026264 | 2024-07-17T18:36:53 Z | ach00 | Type Printer (IOI08_printer) | C++14 | 53 ms | 8168 KB |
#include <bits/stdc++.h> using namespace std; bool cmp(const string &s1, const string &s2) { return s1.size() < s2.size(); } int main() { int n; cin >> n; vector<string> words(n); vector<bool> printed(n, false); vector<char> cprint; int pc = 0; for(auto &a : words) cin >> a; sort(words.begin(), words.end(), cmp); string biggest_word = words[n-1]; vector<char> ans; vector<pair<int, string>> prefixsort; for(int i = 0; i < n-1; i++) { int cnt = 0; for(int j = 0; j < words[i].size(); j++) { if(words[i][j] == biggest_word[j]) cnt++; else break; } prefixsort.push_back({cnt, words[i]}); } prefixsort.push_back({biggest_word.size(), biggest_word}); sort(prefixsort.begin(), prefixsort.end()); for(int i = 0; i < n; i++) { string word = prefixsort[i].second; int cnt = 0; for(int j = 0; j < cprint.size(); j++) { if(cprint[j] == word[j]) cnt++; else break; } while(cprint.size() != cnt) { ans.push_back('-'); cprint.pop_back(); } for(int j = cnt; j < word.size(); j++) { cprint.push_back(word[j]); ans.push_back(word[j]); } ans.push_back('P'); } cout << ans.size() << '\n'; for(auto &s : ans) { cout << s << '\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 360 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 2 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 3 ms | 604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 828 KB | Output is correct |
2 | Correct | 8 ms | 1344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 1620 KB | Output is correct |
2 | Correct | 9 ms | 1880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 3360 KB | Output is correct |
2 | Correct | 44 ms | 7276 KB | Output is correct |
3 | Correct | 32 ms | 5608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 3272 KB | Output is correct |
2 | Correct | 53 ms | 8164 KB | Output is correct |
3 | Correct | 40 ms | 6376 KB | Output is correct |
4 | Correct | 53 ms | 8168 KB | Output is correct |