Submission #782330

# Submission time Handle Problem Language Result Execution time Memory
782330 2023-07-13T20:12:05 Z faruk Mechanical Doll (IOI18_doll) C++17
37 / 100
93 ms 17324 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]);
    }

    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)
      |            ~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 32 ms 8368 KB Output is correct
3 Correct 28 ms 7152 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 3824 KB Output is correct
6 Correct 44 ms 10968 KB Output is correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 32 ms 8368 KB Output is correct
3 Correct 28 ms 7152 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 3824 KB Output is correct
6 Correct 44 ms 10968 KB Output is correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 32 ms 8368 KB Output is correct
3 Correct 28 ms 7152 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 3824 KB Output is correct
6 Correct 44 ms 10968 KB Output is correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Output is partially correct
2 Correct 33 ms 6680 KB Output is correct
3 Partially correct 53 ms 12060 KB Output is partially correct
4 Partially correct 61 ms 11612 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Output is partially correct
2 Correct 33 ms 6680 KB Output is correct
3 Partially correct 53 ms 12060 KB Output is partially correct
4 Partially correct 61 ms 11612 KB Output is partially correct
5 Partially correct 83 ms 15160 KB Output is partially correct
6 Partially correct 85 ms 16500 KB Output is partially correct
7 Partially correct 83 ms 16020 KB Output is partially correct
8 Partially correct 93 ms 17324 KB Output is partially correct
9 Partially correct 54 ms 11696 KB Output is partially correct
10 Partially correct 84 ms 16480 KB Output is partially correct
11 Partially correct 84 ms 16432 KB Output is partially correct
12 Partially correct 55 ms 10916 KB Output is partially correct
13 Partially correct 54 ms 10796 KB Output is partially correct
14 Partially correct 53 ms 10436 KB Output is partially correct
15 Partially correct 54 ms 10000 KB Output is partially correct
16 Partially correct 2 ms 596 KB Output is partially correct
17 Partially correct 45 ms 9408 KB Output is partially correct
18 Partially correct 45 ms 9108 KB Output is partially correct
19 Partially correct 47 ms 9536 KB Output is partially correct
20 Partially correct 65 ms 13076 KB Output is partially correct
21 Partially correct 74 ms 14608 KB Output is partially correct
22 Partially correct 73 ms 12032 KB Output is partially correct