# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
115191 | CaroLinda | Type Printer (IOI08_printer) | C++14 | 7 ms | 896 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 ;
int separa = 1 ;
vector<char> ans ;
bool marc[MAXN*20] ;
void add( char str[] )
{
int t = strlen(str) ;
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;
}
void dfs(int x)
{
if(marc[x]) printf("P\n") ;
int ok= -1 ;
lp(i,0,26)
{
if( trie[x][i] == separa ) { ok = i+'a' ; continue ; }
if(trie[x][i] == 0) continue ;
printf("%c\n", i+'a') ;
dfs( trie[x][i] ) ;
printf("-\n") ;
}
if(ok!=-1)
{
printf("%c\n" , ok) ;
dfs(separa++) ;
}
}
int main()
{
scanf("%d", &n) ;
char v[25][MAXN] ;
scanf(" %s", v[0]) ;
lp(i,1,n)
{
scanf(" %s",v[i]);
if( strlen(v[i]) > strlen(v[0]) ) swap(v[i], v[0]) ;
}
lp(i,0,n) add(v[i]) ;
printf("%d\n" , cnt*2 - strlen(v[0]) + n ) ;
dfs(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... |