// Src : Vux2Code
// Note : none
#include <bits/stdc++.h>
#define pq_rvs pll,vector<pll>,greater<pll>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
struct Edge {ll u, v, w;};
const ll maxN = 2e5 + 5, inf64 = 1e18, mod = 1e9 + 7, maxLog = 20;
ll t = 1;
ll n;
string s [maxN], lg;
vector <char> ans;
ll pre (string x, string y) {
ll siz = min (x. size (), y. size ());
for (int i = 0; i < siz; i ++) {
if (x [i] != y [i]) return i;
}
return siz;
}
bool cmp (string x, string y) {
ll tmp1 = pre (x, lg), tmp2 = pre (y, lg);
if (tmp1 == tmp2) return x < y;
return tmp1 < tmp2;
}
void solve () {
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> s [i];
if (lg. size () < s [i]. size ()) lg = s [i];
}
sort (s + 1, s + n + 1, cmp);
for (char i : s [1]) ans. push_back (i);
ans. push_back ('P');
for (int i = 2; i <= n; i ++) {
ll tmp = pre (s [i - 1], s [i]);
for (int j = s [i - 1]. size () - 1; j >= tmp; j --) ans. push_back ('-');
for (int j = tmp; j <= s [i]. size () - 1l; j ++) ans. push_back (s [i] [j]);
ans. push_back ('P');
}
cout << ans. size () << '\n';
for (char i : ans) cout << i << '\n';
}
int main (){
ios::sync_with_stdio (0);
cin. tie (0);
cout. tie (0);
// #define task "chill"
// freopen (task".inp", "r", stdin);
// freopen (task".out", "w", stdout);
//cin >> t;
while (t --) solve ();
return 0;
}
Compilation message
printer.cpp: In function 'void solve()':
printer.cpp:46:29: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
46 | for (int j = tmp; j <= s [i]. size () - 1l; j ++) ans. push_back (s [i] [j]);
| ~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6744 KB |
Output is correct |
2 |
Correct |
3 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6488 KB |
Output is correct |
2 |
Correct |
3 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
3 ms |
6724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6748 KB |
Output is correct |
2 |
Correct |
6 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7004 KB |
Output is correct |
2 |
Correct |
15 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
7388 KB |
Output is correct |
2 |
Correct |
22 ms |
7000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
8140 KB |
Output is correct |
2 |
Correct |
69 ms |
10436 KB |
Output is correct |
3 |
Correct |
63 ms |
9312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
7684 KB |
Output is correct |
2 |
Correct |
82 ms |
11212 KB |
Output is correct |
3 |
Correct |
67 ms |
9760 KB |
Output is correct |
4 |
Correct |
79 ms |
10960 KB |
Output is correct |