# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
164261 | kimbj0709 | Type Printer (IOI08_printer) | C++17 | 171 ms | 5212 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 int long long
string longest;
bool comp(string a,string b){
int lpa = 0,lpb = 0;
for(int i=0;i<a.length();i++){
if(a.at(i)==longest.at(i)){
lpa++;
}
else{
break;
}
}
for(int i=0;i<b.length();i++){
if(b.at(i)==longest.at(i)){
lpb++;
}
else{
break;
}
}
if(lpa>lpb){
return 0;
}
else if(lpa<lpb){
return 1;
}
else{
return a<b;
}
}
int32_t main() {
string input;
vector<string> vect1;
int no_of_input;
vector<char> ans;
cin >> no_of_input;
for(int i=0;i<no_of_input;i++){
cin >> input;
vect1.push_back(input);
if(input.length()>longest.length()){
longest = input;
}
}
sort(vect1.begin(),vect1.end(),comp);
string rn = "";
for(int i=0;i<vect1.size();i++){
string curr = vect1[i];
while(rn.length()>curr.length()){
ans.push_back('-');
rn.pop_back();
}
for(int j=0;j<rn.length();j++){
if(rn.at(j)!=curr.at(j)){
for(int k=rn.length()-1;k>=j;k--){
ans.push_back('-');
rn.pop_back();
}
goto cont;
}
}
cont : ;
for(int j=rn.length();j<curr.length();j++){
ans.push_back(curr.at(j));
rn += curr.at(j);
}
ans.push_back('P');
}
cout << ans.size() << "\n";
for(auto k:ans){
cout << k << "\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... |