# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1011897 | kaopj | Type Printer (IOI08_printer) | C++17 | 72 ms | 4688 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#define lgm cin.tie(0)->sync_with_stdio(0);
#define ll long long
using namespace std;
string maxi="";
int pref(string s1, string s2) {
int i;
for(i=0; i<min(s1.size(), s2.size()); i++) {
if(s1[i] != s2[i]) return i;
}
return i;
}
static bool cmp(string&a,string&b) {
int x=pref(a,maxi);
int y=pref(b,maxi);
if (a == maxi) {
return false;
}
if (b == maxi) {
return true;
}
if (x != y) {
return x<y;
}
return a < b;
}
int main() {
ll n;
cin >> n;
vector<string> p(n+1);
for (int i=1;i<=n;i++) {
cin >> p[i];
if (p[i].size() > maxi.size()) {
maxi = p[i];
}
}
sort(p.begin()+1,p.end(),cmp);
int pr,mx=0;
for(int i=1; i<=n; i++) {
pr = pref(p[i-1], p[i]);
mx += p[i-1].size() + p[i].size() - 2*pr;
}
cout << mx+n << '\n';
for(int i=1; i<=n; i++) {
pr = pref(p[i-1], p[i]);
for(int j=p[i-1].size(); j>pr; j--) {
cout << "-\n";
}
for(int j=pr; j<p[i].size(); j++) {
cout << p[i][j] << '\n';
}
cout << "P\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |