답안 #415992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
415992 2021-06-01T19:21:26 Z fvogel499 Type Printer (IOI08_printer) C++14
0 / 100
46 ms 44868 KB
/*
File created on 06/01/2021 at 20:53:10.
Link to problem: https://oj.uz/problem/view/IOI08_printer
Description: use a trie structures
Time complexity: O(N)
Space complexity: O(N)
Status: DEV
Copyright: Ⓒ 2021 Francois Vogel
*/

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <queue>
#include <cstring>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;

#define pii pair<int, int>
#define f first
// #define s second

#define pb push_back
#define ins insert
#define cls clear

#define ll long long

vector<char> steps;
int proc;

struct Node {
    Node(char lt, int ld) {
        t = lt;
        d = ld;
        md = d;
        words = 0;
        for (int i = 0; i < 26; i++) exist[i] = nullptr;
    }
    void add(string& s, int k) {
        if (k == s.size()) {
            words++;
            return;
        }
        int i = s[k]-'a';
        if (exist[i] == nullptr) {
            exist[i] = new Node(char(i)+'a', d+1);
            c.pb(exist[i]);
        }
        exist[i]->add(s, k+1);
        md = max(md, exist[i]->md);
    }
    int words, d, md;
    char t;
    Node* exist [26];
    vector<Node*> c;
};

void dfs(Node* i) {
    for (int j = 0; j < i->words; j++) {
        steps.pb('P');
        proc--;
    }
    for (Node* j : i->c) {
        if (j->md == i->md) continue;
        steps.pb(j->t);
        dfs(j);
        if (proc > 0) steps.pb('-');
    }
    for (Node* j : i->c) {
        if (j->md != i->md) continue;
        steps.pb(j->t);
        dfs(j);
        if (proc > 0) steps.pb('-');
    }
}

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    Node* root = new Node('$', 0);

    int n;
    cin >> n;
    string ls;
    for (int i = 0; i < n; i++) {
        cin >> ls;
        root->add(ls, 0);
    }

    proc = n;
    // dfs(root);

    cout << steps.size() << endl;
    for (char i : steps) cout << i << endl;

    int d = 0;
    d++;
}

Compilation message

printer.cpp: In member function 'void Node::add(std::string&, int)':
printer.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if (k == s.size()) {
      |             ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 204 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 460 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2124 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 7116 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 17876 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 44868 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 34780 KB didn't print every word
2 Halted 0 ms 0 KB -