답안 #782334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782334 2023-07-13T20:15:02 Z faruk 자동 인형 (IOI18_doll) C++17
53 / 100
87 ms 15744 KB
#include "doll.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> X, Y, C;
struct trigger {
    int id;
    int type;

    trigger() {}
    trigger(int typ)  {
        if (typ != 0) {
            id = typ;
            type = 1;
        } else {
            id = X.size();
            X.push_back(0);
            Y.push_back(0);
            type = 0;
        }
    }

    void connect_parent(int par) {
        C[par] = -id;
    }

    void connect_X(trigger x) {
        if (x.type == 0)
            X[id - 1] = -x.id;
        else
            X[id - 1] = x.id;
    }

    void connect_Y(trigger y) {
        if (y.type == 0) 
            Y[id - 1] = -y.id;
        else
            Y[id - 1] = y.id;
    }
};

void set_idxs(int curr, int idx, int depth, int max_node, trigger node, vector<trigger> &targets) {
    if (curr * 2 >= max_node) {
        int xi = idx, yi = idx + (1 << depth);
        node.connect_X(trigger(targets[xi]));
        node.connect_Y(trigger(targets[yi]));
        return;
    }
    
    trigger xnode(0);
    trigger ynode(0);
    set_idxs(curr*2, idx, depth + 1, max_node, xnode, targets);
    set_idxs(curr*2+1, idx + (1 << depth), depth + 1, max_node, ynode, targets);
    node.connect_X(xnode);
    node.connect_Y(ynode);
}

void create_device(int node, vector<trigger> targets) {
    int siz = 2, needed = 2;
    while (siz < targets.size())
        siz *= 2, needed += siz;
    trigger root(0); root.connect_parent(node);
    while (targets.size() < siz)
    {
        targets.push_back(root);
        swap(targets[targets.size() - 1], targets[targets.size() - 2]);
    }
    set_idxs(1, 0, 0, siz, root, targets);
}

void create_circuit(int M, std::vector<int> A) {
    int N = A.size();
    C.resize(M+1);
    C[0] = A[0];
    vector<vector<trigger> > targets(M+1);
    for (int i = 0; i < N; i++) {
        int next = i == N - 1 ? 0 : A[i + 1];
        targets[A[i]].push_back(trigger(next));
    }
    for (int i = 1; i <= M; i++) 
    {
        if (!targets[i].empty())
            create_device(i, targets[i]);
    }
    X.pop_back();
    Y.pop_back();

    answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_device(int, std::vector<trigger>)':
doll.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<trigger>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     while (siz < targets.size())
      |            ~~~~^~~~~~~~~~~~~~~~
doll.cpp:64:27: warning: comparison of integer expressions of different signedness: 'std::vector<trigger>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     while (targets.size() < siz)
      |            ~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 33 ms 7848 KB Output is correct
3 Correct 28 ms 6728 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 10 ms 3796 KB Output is correct
6 Correct 50 ms 10312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 33 ms 7848 KB Output is correct
3 Correct 28 ms 6728 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 10 ms 3796 KB Output is correct
6 Correct 50 ms 10312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 36 ms 8132 KB Output is correct
9 Correct 45 ms 10772 KB Output is correct
10 Correct 63 ms 12472 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 33 ms 7848 KB Output is correct
3 Correct 28 ms 6728 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 10 ms 3796 KB Output is correct
6 Correct 50 ms 10312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 36 ms 8132 KB Output is correct
9 Correct 45 ms 10772 KB Output is correct
10 Correct 63 ms 12472 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 86 ms 13924 KB Output is correct
15 Correct 37 ms 7496 KB Output is correct
16 Correct 64 ms 11296 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 69 ms 13344 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 32 ms 5700 KB Output is correct
3 Partially correct 51 ms 11084 KB Output is partially correct
4 Partially correct 58 ms 10080 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 32 ms 5700 KB Output is correct
3 Partially correct 51 ms 11084 KB Output is partially correct
4 Partially correct 58 ms 10080 KB Output is partially correct
5 Partially correct 78 ms 13716 KB Output is partially correct
6 Partially correct 81 ms 15036 KB Output is partially correct
7 Partially correct 80 ms 14560 KB Output is partially correct
8 Partially correct 87 ms 15744 KB Output is partially correct
9 Partially correct 52 ms 10796 KB Output is partially correct
10 Partially correct 85 ms 15080 KB Output is partially correct
11 Partially correct 82 ms 14904 KB Output is partially correct
12 Partially correct 53 ms 9920 KB Output is partially correct
13 Partially correct 54 ms 9900 KB Output is partially correct
14 Partially correct 52 ms 9532 KB Output is partially correct
15 Partially correct 50 ms 8952 KB Output is partially correct
16 Partially correct 2 ms 596 KB Output is partially correct
17 Partially correct 44 ms 8420 KB Output is partially correct
18 Partially correct 44 ms 8096 KB Output is partially correct
19 Partially correct 46 ms 8620 KB Output is partially correct
20 Partially correct 64 ms 11596 KB Output is partially correct
21 Partially correct 72 ms 13100 KB Output is partially correct
22 Partially correct 58 ms 10536 KB Output is partially correct