#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);}}
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); sort(whole(s));
vector<ll> common(N,0); ll thisind, nxtind; ll M; ll sum=0;
REP(i,0,N)
{
thisind = i; nxtind = i+1; if(nxtind==N) {nxtind=0;}
M = min(s[thisind].size(), s[nxtind].size());
REP(j,0,M) {if(s[thisind][j]==s[nxtind][j]) {common[i]++;} else {break;}}
sum+=(2*s[i].size()); sum-=(2*common[i]);
}
ll bestind=-1; ll bestans = INF; ll thisans;
REP(i,0,N)
{
thisind = i; nxtind = i+1; if(nxtind==N) {nxtind=0;}
thisans = N+sum-s[thisind].size()+2*common[thisind];
if(thisans<bestans) {bestans=thisans; bestind=i;}
}
cout<<bestans<<endl; thisind = (bestind+1)%N;
REP(j,0,s[thisind].size()) {cout<<s[thisind][j]<<endl;}
cout<<"P"<<endl; ll C;
REP(i,0,N-1)
{
REP(j,0,s[thisind].size()-common[thisind]) {cout<<"-"<<endl;}
C = common[thisind];
thisind++; thisind%=N;
REP(j,C,s[thisind].size()) {cout<<s[thisind][j]<<endl;}
cout<<"P"<<endl;
}
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")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
684 KB |
Output is correct |
2 |
Incorrect |
109 ms |
1016 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
346 ms |
1856 KB |
Output is correct |
2 |
Correct |
738 ms |
3656 KB |
Output is correct |
3 |
Incorrect |
386 ms |
3148 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
297 ms |
1736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |