Submission #260908

# Submission time Handle Problem Language Result Execution time Memory
260908 2020-08-11T07:31:52 Z Alexa2001 Mechanical Doll (IOI18_doll) C++17
10 / 100
2 ms 368 KB
#include "doll.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> x, y, c;
vector<bool> state;

int n, k, e, nodes = 1;


void create_tree(int node, int sz)
{
    if(sz == 2)
    {
        if(e & 1)
        {
            x[node] = 1;
            y[node] = 0;
        }
        else x[node] = y[node] = 0;

        return;
    }

    if(e & (sz/2))
        x[node] = 1;
    else
    {
        x[node] = ++nodes;
        create_tree(nodes, sz/2);
    }

    y[node] = ++nodes;
    create_tree(nodes, sz/2);
}

void place(int number, int node = 1)
{
    if(state[node] == 0)
    {
        state[node] = 1;

        if(x[node] == 0)
        {
            x[node] = number;
            return;
        }
        else place(number, x[node]);
    }
    else
    {
        state[node] = 0;

        if(y[node] == 0)
        {
            y[node] = number;
            return;
        }
        else place(number, y[node]);
    }
}

void create_circuit(int M, vector<int> A)
{
    n = A.size();

    c.resize(M+1);
    x.resize(10*n);
    y.resize(10*n);

    state.resize(10*n);

    for(k=1; (1<<k) < n; ++k);

    e = (1<<k) - n;

    create_tree(1, (1<<k));

    int i;
    for(i=1; i<n; ++i)
        place(-A[i]);

    place(0);

    for(i=1; i<=nodes; ++i)
        x[i] = -x[i], y[i] = -y[i];

    c[0] = A[0];
    for(i=1; i<=M; ++i)
        c[i] = -1;

    x.erase(x.begin());
    y.erase(y.begin());

    while(x.size() > nodes) x.pop_back();
    while(y.size() > nodes) y.pop_back();

    answer(c, x, y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:96:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   96 |     while(x.size() > nodes) x.pop_back();
      |           ~~~~~~~~~^~~~~~~
doll.cpp:97:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   97 |     while(y.size() > nodes) y.pop_back();
      |           ~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -