#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro "<<i<<endl
#define INF 1000000000000000000LL
#define EPS ((ld)0.00000000001)
#define pi ((ld)3.141592653589793)
#define VV(vvvv,NNNN,xxxx); REP(iiiii,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
ll LCP(string a, string b)
{
ll M = min(a.size(),b.size());
ll ans=0;
REP(i,0,M) {if(a[i]==b[i]) {ans++;} else {break;}}
return ans;
}
string cur;
void print(string s)
{
ll lcp = LCP(s,cur);
while(cur.size()>lcp) {cout<<"-"<<"\n"; cur.pop_back();}
REP(i,cur.size(), s.size()) {cout<<s[i]<<"\n";}
cout<<"P"<<endl;
cur=s;
}
void print_all(vector<string> s)
{
cur="";
REP(i,0,s.size()) {print(s[i]);}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cout.precision(20);
ll N; vector<string> s; cin>>N; In<string>(s,N);
ll ind=0; REP(i,1,N) {if(s[i].size()>s[ind].size()) {ind=i;}}
vector<pair<ll,string> > to_order;
REP(i,0,N) {to_order.pb({LCP(s[i],s[ind]),s[i]});}
sort(whole(to_order));
vector<string> to_print; REP(i,0,N) {to_print.pb(to_order[i].ss);}
ll ans = N; REP(i,0,N) {ans+=(2*to_print[i].size());} ans-=to_print[N-1].size();
REP(i,0,N-1) {ans-=(2*LCP(to_print[i],to_print[i+1]));}
cout<<ans<<endl;
print_all(to_print);
return 0;
}
Compilation message
printer.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization ("O3")
|
printer.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization ("unroll-loops")
|
printer.cpp: In function 'void print(std::string)':
printer.cpp:57:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
57 | while(cur.size()>lcp) {cout<<"-"<<"\n"; cur.pop_back();}
| ~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1116 KB |
Output is correct |
2 |
Correct |
13 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
2200 KB |
Output is correct |
2 |
Correct |
19 ms |
2488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
4356 KB |
Output is correct |
2 |
Correct |
57 ms |
7612 KB |
Output is correct |
3 |
Correct |
47 ms |
7376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
4732 KB |
Output is correct |
2 |
Correct |
72 ms |
9032 KB |
Output is correct |
3 |
Correct |
58 ms |
8124 KB |
Output is correct |
4 |
Correct |
66 ms |
8904 KB |
Output is correct |