# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
532941 | 2022-03-04T09:00:46 Z | prvocislo | Type Printer (IOI08_printer) | C++17 | 61 ms | 5576 KB |
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> typedef long long ll; using namespace std; int overlap(const string& a, const string& b) { for (int i = 0; i < a.size() && i < b.size(); i++) if (a[i] != b[i]) return i; return min(a.size(), b.size()); } string s; bool cmp(const string& a, const string& b) { int sa = overlap(s, a), sb = overlap(s, b); if (sa == sb) return a < b; return sa > sb; } 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]; if (v[i].size() > v[0].size()) swap(v[0], v[i]); } s = v[0]; sort(v.begin() + 1, v.end(), cmp); reverse(v.begin(), v.end()); string pr; string ans; for (int i = 0; i < n; i++) { int pf = (i == 0 ? 0 : overlap(v[i - 1], v[i])); while (pr.size() > pf) { pr.pop_back(); ans.push_back('-'); } for (int j = pf; j < v[i].size(); j++) { pr.push_back(v[i][j]); ans.push_back(v[i][j]); } ans.push_back('P'); } cout << ans.size() << "\n"; for (char i : ans) cout << i << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 312 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 2 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 588 KB | Output is correct |
2 | Correct | 9 ms | 1088 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 1240 KB | Output is correct |
2 | Correct | 8 ms | 1100 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 2424 KB | Output is correct |
2 | Correct | 49 ms | 4692 KB | Output is correct |
3 | Correct | 33 ms | 3668 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 2224 KB | Output is correct |
2 | Correct | 57 ms | 5576 KB | Output is correct |
3 | Correct | 35 ms | 4192 KB | Output is correct |
4 | Correct | 61 ms | 5372 KB | Output is correct |