This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define tam(s) (int)s.size()
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, char> pic;
typedef tuple<int, int, int> tii;
const int lim=500001;
int t[lim];
int32_t main(){
fastio;
int n, k=0, l;
string s, ans="";
cin >> n;
map<char, int> m[lim];
rep(i, 0, n){
cin >> s;
int j=0, p=0;
for(char c: s){
auto it = m[j].find(c);
if(it == m[j].end()) m[j][c] = ++k, j=k;
else j=m[j][c];
t[j] = max(t[j], tam(s)-p);
p++;
}
}
auto dfs=[&] (auto self, int i) -> void {
if(m[i].empty()){
ans += 'P';
l = tam(ans);
return;
}
vector<pic> v;
for(auto [a, b] : m[i]) v.eb(t[b], a);
sort(all(v));
for(auto [a, b] : v){
ans += b;
self(self, m[i][b]);
ans += '-';
}
};
dfs(dfs, 0);
cout << l << endl;
rep(i, 0, l) cout << ans[i] << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |