이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x.size())
using namespace std;
const int N = 500000;
int edges[N][27];
vector<int> depth(N, -1);
int counter;
void dfs(int x) {
if (edges[x][26]) {
cout << "P\n";
--counter;
}
for (int i = 0; i <= 20; ++i) {
for (int j = 0; j < 26; ++j) {
if (edges[x][j] != 0 && depth[edges[x][j]] == i) {
cout << (char)('a'+j) << "\n";
dfs(edges[x][j]);
}
}
}
if (counter > 0) cout << "-\n";
}
void solve() {
int n, vs = 1, c;
cin >> n;
string s;
for (int i = 0; i < n; ++i) {
cin >> s;
c = 0;
for (int j = 0; j < sz(s); ++j) {
if (edges[c][s[j]-'a'] == 0) {
edges[c][s[j]-'a'] = vs;
++vs;
}
c = edges[c][s[j]-'a'];
}
depth[c] = 0;
edges[c][26] = 1;
}
for (int i = vs-1; i >= 0; --i) {
for (int j = 0; j < 26; ++j) {
if (edges[i][j] != 0) {
depth[i] = max(depth[i], depth[edges[i][j]]+1);
}
}
}
int ans = ((vs-1)*2)+n-depth[0];
cout << ans << "\n";
counter = n;
dfs(0);
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
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... |