# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
957559 | hirayuu_oj | Type Printer (IOI08_printer) | C++17 | 35 ms | 8620 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]);
}
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');
}
cout<<ans.size()<<"\n";
for(char i:ans){
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... |