# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
959207 | maxFedorchuk | Type Printer (IOI08_printer) | C++17 | 111 ms | 5328 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;
string s="";
int in;
bool cmp(string a,string b)
{
int in1=-1,in2=-1;
for(int i=0;i<a.size();i++)
{
if(a[i]!=s[i])
{
break;
}
in1=i;
}
for(int i=0;i<b.size();i++)
{
if(b[i]!=s[i])
{
break;
}
in2=i;
}
if(in1==in2)
{
return (a<b);
}
return (in1<in2);
}
bool comp(string a,string b)
{
a=a.substr(0,b.size());
return (a==b);
}
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
vector < string > mas;
for(int i=1;i<=n;i++)
{
string a;
cin>>a;
mas.push_back(a);
}
sort(mas.begin(),mas.end());
for(int i=0;i<n;i++)
{
if(s.size()<mas[i].size())
{
s=mas[i];
}
}
sort(mas.begin(),mas.end(),cmp);
vector < char > ans;
s="";
for(auto u:mas)
{
while(!comp(u,s))
{
s=s.substr(0,s.size()-1);
ans.push_back('-');
}
for(int i=s.size();i<u.size();i++)
{
ans.push_back(u[i]);
s+=u[i];
}
ans.push_back('P');
}
cout<<ans.size()<<"\n";
for(auto u:ans)
{
cout<<u<<"\n";
}
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... |