# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
115187 | CaroLinda | Type Printer (IOI08_printer) | C++14 | 477 ms | 21560 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 pii pair<int,int>
#define lp(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ff first
#define ss second
#define pb push_back
const int MAXN = 25005;
const int ALF= 30;
using namespace std ;
int n ;
int trie[MAXN*20][ALF] , cnt ;
vector<char> ans ;
bool marc[MAXN*20] ;
void add( string str )
{
int t = str.size() ;
int cur = 0 ;
lp(i,0,t)
{
int k = str[i] - 'a' ;
if(trie[cur][k] == 0) trie[cur][k] = ++cnt ;
cur = trie[cur][k] ;
}
marc[cur] =true;
}
bool comp(string s1, string s2)
{ return s1.size() > s2.size() ; }
void dfs(int x)
{
vector<pii> v ;
lp(i,0,27)
if( trie[x][i]!= 0 ) v.pb(pii( trie[x][i] , i+'a' )) ;
sort(v.begin() , v.end()) ;
for(int i = v.size()- 1 ; i >= 0 ; i--)
{
char c = v[i].ss;
ans.pb(c) ;
dfs(v[i].ff) ;
ans.pb('-') ;
}
if(marc[x]) ans.pb('P') ;
}
int main()
{
ios_base::sync_with_stdio(false) ;
cin.tie(NULL) ;
cin>>n ;
vector<string> v ;
string s ;
lp(i,0,n) { cin>>s ; v.pb(s) ; }
sort(v.begin() , v.end(), comp ) ;
lp(i,0,n) add(v[i]) ;
dfs(0) ;
cout<<ans.size() - v[0].size() <<endl ;
lp(i,0,ans.size() - v[0].size()) cout<<ans[i]<<endl ;
}
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... |