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<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
//const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second
void solve(){
int n;
cin>>n;
vector<string>arr(n);
string m;
for(string&i:arr){
cin>>i;
if(i.size()>m.size())
m=i;
}
sort(arr.begin(),arr.end());
for(int p=1;p<m.size();p++){
vector<string>pref,suf;
for(int i=0;i<n;i++){
bool matches=true;
if(arr[i].size()<p)
matches=false;
else{
for(int j=0;j<p;j++)
if(m[j]!=arr[i][j])
matches=false;
}
if(matches)
suf.push_back(arr[i]);
else
pref.push_back(arr[i]);
}
arr=pref;
arr.insert(arr.end(),suf.begin(),suf.end());
}
vector<char>res;
string prev;
for(int i=0;i<n;i++){
while(arr[i].substr(0,prev.size())!=prev){
prev.pop_back();
res.push_back('-');
}
while(prev!=arr[i]){
res.push_back(arr[i][(int)prev.size()]);
prev.push_back(arr[i][(int)prev.size()]);
}
res.push_back('P');
}
cout<<res.size()<<"\n";
for(char c:res)
cout<<c<<"\n";
}
int main(){
ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
//freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
int t=1;//cin>>t;
while(t--)solve();
return 0;
}
Compilation message (stderr)
printer.cpp: In function 'void solve()':
printer.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int p=1;p<m.size();p++){
| ~^~~~~~~~~
printer.cpp:40:29: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if(arr[i].size()<p)
| ~~~~~~~~~~~~~^~
# | 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... |