# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705968 | assem_albitar | Type Printer (IOI08_printer) | C++14 | 266 ms | 118184 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>
#define ll long long
#define ld long double
#define mod 1000000007
#define mxe(v) *max_element(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend()
#define F first
#define S second
#define pi pair<ll,ll>
#define assem ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
using namespace std;
const int N=400200;
const double PI=3.1415926535897932384626433;
const double eps = 1e-9;
string getString()
{
char c[(int)21];
//scanf(" %c",&a[i]);
scanf("%s", c);
return c;
//string x = getString();
}
///printf("%d\n",);
///scanf("%d",&);
///cout.precision(10);
///puts("")string
vector<char> ans;
int n;
vector<string> v;
struct trie
{
int cnt,c;
vector<char> a;
unordered_map<char,trie*>child;
trie()
{
cnt=c=0;
//memset(child,0,sizeof child);
}
void add(int i,int j)
{
if(j==v[i].size())
{
c++;
cnt=j;
return;
}
if(child[v[i][j]-'a']==0)
{
child[v[i][j]-'a']=new trie();
child[v[i][j]-'a']->add(i,j+1);
a.push_back(v[i][j]);
}
else
{
child[v[i][j]-'a']->add(i,j+1);
}
if(child[v[i][j]-'a']->cnt>cnt)cnt=child[v[i][j]-'a']->cnt;
}
void get()
{
if(c)
{
ans.push_back('P');
}
bool f=1;
char id='a';
for(int i=0;i<a.size(); i++)
{
if(f&&child[a[i]-'a']!=0&&child[a[i]-'a']->cnt==cnt)
{
f=0;
id=a[i];
}
else if(child[a[i]-'a']!=0)
{
ans.push_back(a[i]);
child[a[i]-'a']->get();
ans.push_back('-');
}
}
if(!f)
{
ans.push_back(id);
child[id-'a']->get();
ans.push_back('-');
}
return;
}
};
int main()
{
scanf("%d",&n);
trie* root=new trie();
for(int i=0; i<n; i++)
{
string q;
q=getString();
v.push_back(q);
root->add(i,0);
}
root->get();
while(ans.back()=='-')ans.pop_back();
printf("%d\n",(int)ans.size());
for(int i=0; i<ans.size(); i++)
{
printf("%c\n",ans[i]);
}
}
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... |