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 main(){
int n; cin >> n;
vector<string> v(n);
for(auto &x : v)cin >> x;
vector<vector<string>> out(21);
vector<int> used(n,0);
int ls = -1, lsn = 0;
for(int i = 0; i < n; ++i){
if((int)v[i].size() > lsn){
lsn = v[i].size();
ls = i;
}
}
for(int i = 0; i < lsn; ++i){
for(int j = 0; j < n; ++j){
if(used[j])continue;
if((int)v[j].size() < i){out[i].push_back(v[j]);used[j] = 1;}
if(v[ls][i] != v[j][i]){out[i].push_back(v[j]);used[j] = 1;}
}
}
for(int i = 0; i < n; ++i){
if(!used[i])out[20].push_back(v[i]);
}
for(int i = 0; i < 21; ++i){
sort(out[i].begin(),out[i].end());
}
string cur;
vector<char> oututo;
for(auto x : out){
for(auto y : x){
int go = min(cur.size(),y.size());
for(int i = 0; i < min((int)cur.size(),(int)y.size()); ++i){
if(cur[i] != y[i]){go = i; break;}
}
while(go < (int)cur.size()){
cur.pop_back();
oututo.push_back('-');
}
for(int i = go; i < (int)y.size(); ++i){
oututo.push_back(y[i]);
cur+=y[i];
}
oututo.push_back('P');
}
}
cout << oututo.size() << "\n";
for(auto x : oututo)cout << x << "\n";
}
# | 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... |