#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;
}
bool cmp(string a , string b){
return a.size() < b.size();
}
void solve(){
int n;
cin >> n;
string arr[n];
for(int i = 0; i < n; i++)cin >> arr[i];
sort(arr,arr + n , cmp);
int mx = 0 , pos = -1;
for(int i = 0; i < n-1 ;i++){
if(arr[i][0] != arr[i + 1][0]){
if(mx < (int)arr[i].size()){
mx = arr[i].size();
pos = i;
}
}
}
if(mx < (int)arr[n-1].size()){
mx = arr[n-1].size();
pos = n-1;
}
string a[n];
int cur = 0;
for(int i = pos + 1; i < n; i++){
a[cur++] = arr[i];
}
for(int i = 0; i <= pos; 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 |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't 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 |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
3260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
3184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |