| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 231585 | AlexLuchianov | Type Printer (IOI08_printer) | C++14 | 239 ms | 99692 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 25000;
int const sigma = 26;
vector<char> sol;
class Trie{
private:
struct Node{
int _scount;
int depth;
Node* son[sigma];
Node(){
_scount = 0;
for(int i = 0; i < sigma; i++)
son[i] = nullptr;
}
};
public:
void _insert(Node* &root, string &s, int ptr){
if(root == nullptr)
root = new Node();
if(s.size() == ptr)
root->_scount++;
else
_insert(root->son[s[ptr] - 'a'], s, ptr + 1);
}
void dfs(Node* &root){
if(root == nullptr)
return ;
root->depth = 1;
for(int h = 0; h < sigma; h++)
if(root->son[h] != nullptr) {
dfs(root->son[h]);
root->depth = max(root->depth, root->son[h]->depth + 1);
}
}
void print(Node* &root, bool discount){
if(root == nullptr)
return ;
for(int h = 0; h < root->_scount; h++)
sol.push_back('P');
int chosen = 0;
for(int h = 0; h < sigma; h++) {
if(root->son[h] == nullptr)
continue;
if(root->son[h]->depth + 1 == root->depth)
chosen = h;
}
if(discount == 0)
chosen = -1;
for(int h = 0; h < sigma; h++){
if(h == chosen)
continue;
if(root->son[h] != nullptr){
sol.push_back(char(h + 'a'));
print(root->son[h], 0);
sol.push_back('-');
}
}
if(-1 != chosen && root->son[chosen] != nullptr){
sol.push_back(char(chosen + 'a'));
print(root->son[chosen], 1);
}
}
Node* root = nullptr;
};
int main()
{
int n;
cin >> n;
Trie trie;
for(int i = 1;i <= n; i++){
string s;
cin >> s;
trie._insert(trie.root, s, 0);
}
trie.dfs(trie.root);
trie.print(trie.root, 1);
cout << sol.size() << '\n';
for(int i = 0; i < sol.size(); i++)
cout << sol[i] << '\n';
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... | ||||
