# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
228878 | 2020-05-03T00:44:33 Z | tri | Type Printer (IOI08_printer) | C++14 | 74 ms | 6636 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; #define pb push_back #define f first #define s second const int MAXN = 3e4; string strs[MAXN]; int lcp(string a, 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 longest; // special comparator that reorders characters in a way such that longest string will go last bool specComp(string a, string b) { for (int i = 0; i < a.size() && i < b.size(); i++) { if (a[i] == b[i]) { continue; } if (a[i] == longest[i]) { return false; } if (b[i] == longest[i]) { return true; } return a[i] < b[i]; } return a.size() < b.size(); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; strs[0] = ""; for (int i = 1; i <= N; i++) { cin >> strs[i]; } sort(strs, strs + N + 1); longest = ""; for (int i = 1; i <= N; i++) { if (strs[i].size() > longest.size()) { longest = strs[i]; } } sort(strs, strs + N + 1, specComp); int count = 0; string output = ""; for (int i = 1; i <= N; i++) { int cLCP = lcp(strs[i - 1], strs[i]); for (int j = 0; j < strs[i - 1].size() - cLCP; j++) { count++; output += "-\n"; } for (int j = cLCP; j < strs[i].size(); j++) { count++; output += strs[i][j]; output += "\n"; } count++; output += "P\n"; } cout << count << endl; cout << output << flush; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 1280 KB | Output is correct |
2 | Correct | 5 ms | 1280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 1280 KB | Output is correct |
2 | Correct | 5 ms | 1280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 1280 KB | Output is correct |
2 | Correct | 5 ms | 1280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 1280 KB | Output is correct |
2 | Correct | 5 ms | 1280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 1408 KB | Output is correct |
2 | Correct | 6 ms | 1408 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 1408 KB | Output is correct |
2 | Correct | 9 ms | 1408 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 1664 KB | Output is correct |
2 | Correct | 17 ms | 2064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 2076 KB | Output is correct |
2 | Correct | 25 ms | 1920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 3248 KB | Output is correct |
2 | Correct | 64 ms | 5868 KB | Output is correct |
3 | Correct | 67 ms | 4528 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 2736 KB | Output is correct |
2 | Correct | 71 ms | 6636 KB | Output is correct |
3 | Correct | 74 ms | 4828 KB | Output is correct |
4 | Correct | 66 ms | 6508 KB | Output is correct |