# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445769 | dxz05 | Type Printer (IOI08_printer) | C++14 | 105 ms | 43712 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 <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define SZ(x) (int)(x).size()
const int MAXN = 1e6 + 3e2;
pair<int, string> str[MAXN];
int main(){
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr); cout.tie(nullptr);
int n;
scanf("%d", &n);
int ind = 0;
for (int i = 1; i <= n; i++){
char c[25];
scanf("%s", &c);
int len = strlen(c);
str[i].second.resize(len);
for (int j = 0; j < len; j++) str[i].second[j] = c[j];
if (str[i].second.size() > str[ind].second.size()) ind = i;
}
string longest = str[ind].second;
for (int i = 1; i <= n; i++){
int j = 0;
while (j < str[i].second.size() && str[i].second[j] == longest[j]) j++;
str[i].first = j;
}
sort(str + 1, str + n + 1);
vector<char> ans;
for (int it = 1; it <= n; it++){
string s = str[it].second, t = str[it - 1].second;
if (SZ(t) > SZ(s)){
int need = SZ(t) - SZ(s);
while (need--) ans.push_back('-');
t.resize(s.size());
}
int cnt = 0;
for (int i = 0; i < min(SZ(t), SZ(s)); i++){
if (t[i] == s[i]) cnt++; else
break;
}
int need = max(0, SZ(t) - cnt);
while (need--){
ans.push_back('-');
}
for (int i = cnt; i < s.size(); i++){
ans.push_back(s[i]);
}
ans.push_back('P');
}
printf("%d\n", SZ(ans));
for (char c : ans) printf("%c\n", c);
return 0;
}
/**
3
print
the
poem
*/
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... |