이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 25000 * 20 + 5;
int cnt = 0, nex[maxn][26], n; string mx = ""; vector<string> vs;
vector<bool> flag(maxn, false), bac(maxn, false); vector<char> ans;
void ins(string& s, bool f) {
int p = 0;
for (int i = 0; i < s.length(); i++) {
int c = s[i] - 'a';
if (!nex[p][c]) nex[p][c] = ++cnt;
p = nex[p][c];
flag[p] = f;
if (i == s.length() - 1) bac[p] = true;
}
}
void dfs(int u) {
if (bac[u]) ans.pb('P');
if (flag[u]) {
for (int i = 0; i < 26; i++) if (!flag[nex[u][i]] && nex[u][i]) ans.pb((char) (i + 'a')), dfs(nex[u][i]), ans.pb('-');
for (int i = 0; i < 26; i++) if (flag[nex[u][i]] && nex[u][i]) ans.pb((char) (i + 'a')), dfs(nex[u][i]), ans.pb('-');
} else {
for (int i = 0; i < 26; i++) if (nex[u][i]) ans.pb((char) (i + 'a')), dfs(nex[u][i]), ans.pb('-');
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
while (n--) {
string s; cin >> s; vs.pb(s);
if (s.length() > mx.length() || (s.length() == mx.length() && s > mx)) mx = s;
}
for (auto& s : vs) if (s != mx) ins(s, false);
ins(mx, true);
flag[0] = true;
dfs(0);
while (ans.back() == '-') ans.pop_back();
cout << ans.size() << "\n";
for (char c : ans) cout << c << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
printer.cpp: In function 'void ins(std::string&, bool)':
printer.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for (int i = 0; i < s.length(); i++) {
| ~~^~~~~~~~~~~~
printer.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | if (i == s.length() - 1) bac[p] = true;
| ~~^~~~~~~~~~~~~~~~~
# | 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... |