# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
588615 | leeh18 | Type Printer (IOI08_printer) | C++17 | 193 ms | 99124 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(x) (int)size(x)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef pair<int, int> pii;
typedef vector<int> vi;
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());
void set_io(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
struct node {
int max_len;
bool check;
array<unique_ptr<node>, 26> ch;
node() : max_len(0), check(false) {}
void insert(const string &s, int pos = 0) {
if (sz(s) == pos) {
check = true;
return;
}
auto c = int(s[pos] - 'a');
if (ch[c] == nullptr) {
ch[c] = make_unique<node>();
}
ch[c]->max_len = max(ch[c]->max_len, sz(s));
ch[c]->insert(s, pos + 1);
}
void dfs(vector<char>& ans) const {
vector<pair<int, int>> pool;
for (int i = 0; i < sz(ch); i++) {
if (ch[i]) {
pool.push_back({ch[i]->max_len, i});
}
}
if (check) {
ans.push_back('P');
}
sort(pool.begin(), pool.end());
for (auto [val, idx] : pool) {
ans.push_back(char('a' + idx));
ch[idx]->dfs(ans);
ans.push_back('-');
}
}
};
void solve() {
int n;
cin >> n;
node trie;
int mx = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
trie.insert(s);
mx = max(mx, sz(s));
}
vector<char> ans;
trie.dfs(ans);
ans.resize(sz(ans) - mx);
cout << ans.size() << '\n';
for (auto x : ans) {
cout << x << '\n';
}
}
auto main() -> signed {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |