#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
bool check(string& a , string& b){
for(int i = 0; i < (int)a.size(); i++){
if(a[i]!=b[i])return 1;
}
return 0;
}
void solve(){
int n;
cin >> n;
string arr[n];
for(int i = 0; i < n; i++)cin >> arr[i];
sa(arr,n);
int mn = 1e9 , pos = -1;
for(int i = 0; i < n-1 ;i++){
if(arr[i][0] != arr[i + 1][0]){
if(mn > (int)arr[i].size()){
mn = arr[i].size();
pos = i;
}
}
}
if(mn > (int)arr[n-1].size()){
mn = arr[n-1].size();
pos = n-1;
}
int j = pos;
while(j >= 0 && arr[j][0] == arr[pos][0]){
j--;
}
string a[n];
int cur = 0;
for(int i = j + 1; i < n; i++){
a[cur++] = arr[i];
}
for(int i = 0; i <= j; i++){
a[cur++] = arr[i];
}
for(int i = 0; i < n; i++)arr[i] = a[i];
vector<char> v;
string s = "";
for(int i = 0; i < n; i++){
while(check(s,arr[i])){
v.pb('-');
s.pop_back();
}
for(int j = s.size(); j < (int)arr[i].size(); j++){
s += arr[i][j];
v.pb(arr[i][j]);
}
v.pb('P');
}
cout << v.size() << '\n';
for(char c : v)cout << c << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
1604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3396 KB |
Output is correct |
2 |
Correct |
45 ms |
6336 KB |
Output is correct |
3 |
Incorrect |
32 ms |
5436 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
3020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |