#include <bits/stdc++.h>
#define pb push_back
#define rs resize
#define debug printf("Hello\n")
#define Pi 3.141592653589793
#define sz(a) ll((a).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define mp make_pair
#define f first
#define s second
#define vt vector
#define rst(a,b) memset((a),(b), sizeof(a))
#define FOR(a, b, c) for (ll a = (b); (a) < (c); ++(a))
#define FORE(a, b, c) for (ll a = (b); (a) <= (c); ++(a))
#define FORR(a, b, c) for (ll a = (b); (a) >= (c); --(a))
#define umap unordered_map
#define len(a) (a).length()
#define pqueue priority_queue
using namespace std;
using vi = vector<int>;
using ui = unsigned int;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using ull = unsigned long long;
using pii = pair<int, int>;
ll e(ll base, ll pwr, ll mm = LLONG_MAX){
if(pwr == 1) return base%mm;;
if(pwr == 0) return 1;
if(pwr % 2 == 1){
ull t = e(base, (pwr-1)/2,mm)%mm;
return (t*t)%mm*base%mm ;
}
if(pwr % 2 == 0){
ull t = e(base, pwr/2, mm)%mm;
return (t*t)%mm;
}
return 0;
}
ll flt(ll a, ll p){
return e(a,p-2,p);
}
ll combination(ll n, ll r){
if(r>n/2)return combination (n,n-r);
ll k=1;
for(ll x=n,j=1;x>n-r||j<=r;--x,++j){
if(x>n-r)k*=x;
if(j<=r)k/=j;
}
return k;
}
vector<ll> getFactor(ll n){
vector<ll> tmp;
vector<ll> ans;
if(n == 1)return vt<ll>{1};
else if(n==2) return vt<ll> {1,2};
for(ll i = 1;i<=ceil(sqrt(n));++i){
if(!(n%i)){
ans.pb(i);
if(i!=n/i && abs(i-(n/i)) != 1)tmp.pb(n/i);
}
}
for(ll i=tmp.size()-1;i>-1;--i){
ans.pb(tmp[i]);
}
return ans;
}
bool isPrime(ll n) {if(n == 1)return 0;for(ll i = 2;i*i <= n;++i){if(!(n%i))return 0;}return 1;}
//DSU---
struct Dsu{
ll v;
vector<ll> parent;
vector<ll> rank;
Dsu(ll V){
v=V;
parent = vector<ll> (v,-1);
rank = vector<ll> (v,1);
}
ll find(ll i){
if(parent[i] == -1)return i;
return parent[i] = find(parent[i]);
}
void un(ll i, ll j){
ll a = find(i), b = find(j);
if(a!=b){
if(rank[a]>rank[b])swap(a,b);
parent[a] = b;
rank[b] += rank[a];
}
}
};
//DSU-END---
struct Mat{
ll w, h;
const int mod = 1e9+7;
vt<vll> m;
Mat(ll W, ll H){
w = W; h = H;
m = vt<vll> (h, vll(w,0));
}
void identity(){
FOR(i,0,w){
m[i][i] = 1;
}
}
Mat operator * (Mat b){
Mat res(b.w,h);
FOR(row, 0, h){
FOR(col, 0, b.w){
FOR(k, 0, w){
res.m[row][col] += (m[row][k] * b.m[k][col]);
}
}
}
return res;
}
};
struct Bit{
ll n;
vll fn;
Bit(){}
Bit(ll N){
n = N+1;
fn = vll (n, 0);
}
void add(ll pos, ll val){
for(pos++; pos<n; pos+=pos&(-pos))fn[pos] += val;
}
ll sum(ll pos){
ll res = 0;
for(pos++; pos>0; pos-=pos&(-pos))res += fn[pos];
return res;
}
ll sum(ll l, ll r){
return sum(r) - sum(l-1);
}
};
//
const int dx[4] = {0,0,-1,1};
const int dy[4] = {1,-1,0,0};
const char dir[4] = {'R', 'L', 'U', 'D'};
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
vt<string> arr;
ll score(string a, string b){
ll c = 0;
FOR(i,0,len(b)){
if(b[i] != a[i])return c;
if(i >= len(a))return c;
c++;
}
return c;
}
bool cmp (const string &a, const string &b){
ll blower = score(a, b);
ll alower = score(b, a);
return (len(a) - blower) < (len(b) - alower);
}
ll score(ll x){
ll c = 0;
FOR(i,0,len(arr[x])){
if(arr[x][i] != arr[x-1][i])return c;
if(i >= len(arr[x-1]))return c;
c++;
}
return c;
}
void solve(){
ll n;cin >> n;
FOR(i,0,n){
string s;cin >> s;
arr.pb(s);
}
sort(all(arr), cmp);
ll cnt = len(arr[0]) + 1;
vt<string> ans;
ans.pb(arr[0] + 'P');
FOR(i,1,n){
ll k = score(i);
ans.pb(string(len(arr[i-1]) - k, '-'));
ans.pb(arr[i].substr(k, len(arr[i])-k) + 'P');
cnt += len(arr[i-1]) - k + len(arr[i]) - k + 1;
}
cout << cnt << endl;
FOR(i,0,sz(ans)){
for(auto x : ans[i]){
cout << x << endl;
}
}
}
int main(){
fastio;
//cout << fixed << setprecision(10);
//freopen("1_02.txt", "r", stdin);
solve();
}
Compilation message
printer.cpp: In function 'll score(std::string, std::string)':
printer.cpp:15:43: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | #define FOR(a, b, c) for (ll a = (b); (a) < (c); ++(a))
| ~~~~^~~~~~
printer.cpp:165:2: note: in expansion of macro 'FOR'
165 | FOR(i,0,len(b)){
| ^~~
printer.cpp:167:8: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
167 | if(i >= len(a))return c;
| ^
printer.cpp: In function 'll score(ll)':
printer.cpp:15:43: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | #define FOR(a, b, c) for (ll a = (b); (a) < (c); ++(a))
| ~~~~^~~~~~
printer.cpp:181:2: note: in expansion of macro 'FOR'
181 | FOR(i,0,len(arr[x])){
| ^~~
printer.cpp:183:8: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
183 | if(i >= len(arr[x-1]))return c;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
972 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
3564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
3780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |