# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969627 | SeenSiravit | Type Printer (IOI08_printer) | C++14 | 1040 ms | 1364 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;
int n;
vector<string> words;
int base = 0;
int find_position(string s , string res){
for(int i=0;i<min(s.length() , res.length());i++){
if(res[i] != s[i]) return i;
}
return min(s.length() , res.length());
}
int main(){
cin>> n;
words.assign(n , "");
for(int i=0;i<n;i++){
cin>> words[i];
if(words[i].length() > words[base].length()) base = i;
}
int ans = 0;
stack<char> st;
swap(words[0] , words[base]);
for(int i=0;i<n-1;i++){
int pos = i+1 , mn = INT_MAX , idx = 0;
for(int j=i+1;j<n;j++){
int dummy = find_position(words[j] , words[i]);
int op = words[i].length() + words[j].length() - 2*dummy;
if(op < mn) pos = j , mn = op , idx = dummy;
}
ans += mn + 1;
st.push('P');
int curr = words[i].length() - 1;
while(curr >= idx) st.push(words[i][curr--]);
for(int j=words[pos].length()-1;j>=idx;j--) st.push('-');
swap(words[i+1] , words[pos]);
// cout<< ans << "\n";
}
ans += words[n-1].length() + 1;
cout<< ans << "\n";
for(auto c : words[n-1]) cout<< c << "\n";
cout<< "P" << "\n";
while(!st.empty()) cout<< st.top() << "\n" , st.pop();
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... |