# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
957566 | hirayuu_oj | Type Printer (IOI08_printer) | C++17 | 39 ms | 9040 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>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,a,b) for(int i=a; i<(b); i++)
#define all(x) x.begin(),x.end()
using ll=long long;
const int INF=INT_MAX>>1;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
vector<string> s(n);
rep(i,n){
cin>>s[i];
}
sort(all(s));
rep(i,n){
s.push_back(s[i]);
}
rep(i,n){
s.push_back(s[i]);
}
vector<char> fin;
rep(_,2){
int mx=-INF;
int pos=0;
rep(i,n){
ll ng=0;
rep(j,min(s[i].size(),s[i+1].size())){
if(s[i][j]==s[i+1][j]){
ng++;
}
else{
break;
}
}
int now=(s[i].size()+s[i+1].size()-ng*2)-s[i+1].size();
if(mx<now){
mx=now;
pos=i+1;
}
}
vector<char> ans;
for(char i:s[pos]){
ans.push_back(i);
}
ans.push_back('P');
rep2(i,pos,pos+n-1){
ll ng=0;
rep(j,min(s[i].size(),s[i+1].size())){
if(s[i][j]==s[i+1][j]){
ng++;
}
else{
break;
}
}
rep(j,s[i].size()-ng){
ans.push_back('-');
}
rep2(j,ng,s[i+1].size()){
ans.push_back(s[i+1][j]);
}
ans.push_back('P');
}
if(fin.size()==0 or fin.size()>=ans.size()){
fin=ans;
}
reverse(all(s));
}
cout<<fin.size()<<"\n";
for(char i:fin){
cout<<i<<"\n";
}
}
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... |