#include <bits/stdc++.h>
#define ll long long
using namespace std;
string maxi="";
int pref(string a) {
int cnt=0;
while (a[cnt] == maxi[cnt]) {
cnt++;
}
return cnt;
}
static bool cmp(string&a,string&b) {
int x=pref(a);
int y=pref(b);
if (x != y) {
return x<y;
}
return a.size() < b.size();
}
int main() {
ll n;
cin >> n;
vector<string> p(n);
for (int i=0;i<n;i++) {
cin >> p[i];
if (p[i].size() > maxi.size()) {
maxi = p[i];
}
}
sort(p.begin(),p.end(),cmp);
string curr="";
string ans="";
for (int i=0;i<n;i++) {
while (curr.size() != 0 && curr != p[i].substr(0,curr.size())) {
ans+="-";
curr.pop_back();
}
ans+=p[i].substr(curr.size(),p[i].size()-curr.size());
curr=p[i];
ans+="P";
}
n = ans.size();
for (int i=0;i<n;i++) {
cout << ans[i] <<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
436 KB |
Expected integer, but "t" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "n" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Expected integer, but "h" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Expected integer, but "x" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Expected integer, but "r" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Expected integer, but "a" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
860 KB |
Expected integer, but "e" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1264 KB |
Expected integer, but "o" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
2632 KB |
Expected integer, but "s" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
2548 KB |
Expected integer, but "f" found |
2 |
Halted |
0 ms |
0 KB |
- |