# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
964369 | 2024-04-16T17:54:20 Z | anango | Type Printer (IOI08_printer) | C++17 | 1000 ms | 7504 KB |
#include <bits/stdc++.h> #define int long long using namespace std; int pref(string s1, string s2) { for (int i=0; i<s1.size(); i++) { if (i>=s2.size() || s1[i]!=s2[i]) { return i; } } return min(s1.size(), s2.size()); } signed main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int n; cin >> n; vector<string> v; int ma=0; int mpos=-1; vector<int> answers(n); for (int i=0; i<n; i++) { string s; cin >> s; v.push_back(s); if (s.size()>ma) { ma=s.size(); mpos=i; } } string mword=v[mpos]; for (int i=0; i<n; i++) { answers[i] = pref(v[i], mword); } vector<int> w; for (int i=0; i<n; i++) { w.push_back(i); } sort(w.begin(), w.end(), [&](const int s1, const int s2) { if (answers[s1]!=answers[s2]) { return answers[s1]<answers[s2]; } return v[s1]<v[s2]; }); vector<string> v2(n); for (int i=0; i<n; i++) { v2[i] = v[w[i]]; } int tot=0; vector<char> prints; string current; for (int i=0; i<n; i++) { int t=pref(current,v2[i]); while (current.size()>t) { prints.push_back('-'); current.pop_back(); } for (int j=current.size(); j<v2[i].size(); j++) { prints.push_back(v2[i][j]); } current = v2[i]; prints.push_back('P'); } cout << prints.size() << endl; for (auto i:prints) { cout << i << endl; } }
Compilation message
# | 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 | 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 | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 348 KB | Output is correct |
2 | Correct | 10 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 572 KB | Output is correct |
2 | Correct | 21 ms | 604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 59 ms | 1112 KB | Output is correct |
2 | Correct | 142 ms | 1400 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 163 ms | 1876 KB | Output is correct |
2 | Correct | 57 ms | 2292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 403 ms | 3524 KB | Output is correct |
2 | Correct | 839 ms | 6472 KB | Output is correct |
3 | Correct | 454 ms | 5976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 320 ms | 3720 KB | Output is correct |
2 | Execution timed out | 1024 ms | 7504 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |