# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1026291 | 2024-07-17T19:05:41 Z | fv3 | Type Printer (IOI08_printer) | C++14 | 25 ms | 2296 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll INF = 1ll << 60ll; vector<int> order(26); bool compare(string a, string b) { for (int i = 0; i < min(a.size(), b.size()); i++) { if (order[a[i]-'a'] > order[b[i]-'a']) return true; if (order[a[i]-'a'] < order[b[i]-'a']) return false; } return a.size() < b.size(); } string printSolution(vector<string>&bestPerm) { string res = ""; string lastWord = ""; for (auto w : bestPerm) { int i = 0; for (; i < min(lastWord.size(), w.size()); i++) { if (w[i] != lastWord[i]) break; } for (int j = 0; j < lastWord.size() - i; j++) res += "-"; for (; i < w.size(); i++) res += w[i]; res += "P"; lastWord = w; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<string> words(N); string longest = ""; for (int i = 0; i < N; i++) { cin >> words[i]; if (words[i].size() > longest.size()) longest = words[i]; } int x = 1; for (auto c : longest) { if (order[c-'a']) continue; order[c-'a'] = x++; } for (int i = 0; i < 26; i++) { if (order[i] == 0) order[i] = x++; } sort(words.begin(), words.end(), compare); string res = printSolution(words); cout << res.size() << '\n'; for (auto c : res) { cout << c << '\n'; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 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 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 728 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 1264 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 25 ms | 2296 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 2036 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |