# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1104223 | dzhoz0 | Type Printer (IOI08_printer) | C++17 | 142 ms | 232568 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
ghmt the cutie :3
UwU
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define f first
#define s second
#define pii pair<int, int>
#define vi vector<int>
const int MOD = 1'000'000'000 + 7;
void setIO(string name = "")
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef LOCAL
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
if (!name.empty())
{
freopen((name + ".INP").c_str(), "r", stdin);
freopen((name + ".OUT").c_str(), "w", stdout);
}
#endif
}
const int MAXNODES = 1e6;
struct Node {
int child[26];
int cnt;
bool stop;
int mx;
Node() {
memset(child, -1, sizeof(child));
stop = 0;
cnt = 0;
mx = 0;
}
};
Node trie[MAXNODES + 5];
int sz = 0;
void insert(string &s) {
int pos = 0;
for(char c : s) {
if(trie[pos].child[c - 'a'] == -1) {
trie[pos].child[c - 'a'] = ++sz;
}
pos = trie[pos].child[c - 'a'];
trie[pos].cnt++;
trie[pos].mx = max(trie[pos].mx, (int)s.size());
}
trie[pos].stop = 1;
}
vector<char> ops;
void traverse(int id) {
if(trie[id].stop == 1) ops.push_back('P');
vector<pair<int, char>> v;
for(char c = 'a'; c <= 'z'; c++) {
if(trie[id].child[c - 'a'] != -1) {
// ops.push_back(c);
// traverse(trie[id].child[c - 'a']);
v.push_back({trie[trie[id].child[c - 'a']].mx, c});
}
}
sort(v.begin(), v.end());
for(auto it : v) {
ops.push_back(it.s);
traverse(trie[id].child[it.s - 'a']);
}
ops.push_back('-');
}
void solve()
{
int n; cin >> n;
vector<string> a(n);
for(string &s : a) {
cin >> s;
insert(s);
}
traverse(0);
while(ops.back() != 'P') ops.pop_back();
cout << ops.size() << '\n';
for(char c : ops) cout << c << '\n';
}
signed main()
{
setIO();
int t = 1;
// cin >> t;
while (t--)
solve();
}
컴파일 시 표준 에러 (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... |