Submission #740477

# Submission time Handle Problem Language Result Execution time Memory
740477 2023-05-12T14:16:51 Z danikoynov Mechanical Doll (IOI18_doll) C++14
53 / 100
152 ms 31492 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 2e5 + 10;

int n, m;
vector < int > g[maxn];
vector < int > c, x, y;

struct state
{
    int dev, lf_child, rf_child;
    vector < int > fin;

    state()
    {
        dev = 0;
        lf_child = rf_child = -1;
        fin.clear();
    }
};

void create_node(int v)
{
    if (g[v].size() == 0)
        return;

        if (g[v].size() == 1)
        {
            c[v] = g[v][0];
            return;
        }
        int nec = 2, st = 0;
        while(nec < g[v].size())
            nec *= 2, st ++;
        ///cout << g[v].size() << " " << nec << " : " << st << endl;
        vector < state > gen;
        int sz = x.size();
        state it;
        it.dev = ++ sz;
        c[v] = -it.dev;
        it.fin.push_back(1);
        gen.push_back(it);
        for (int step = 0; step < st; step ++)
        {
            vector < state > new_gen;
            for (int i = 0; i < gen.size(); i ++)
            {
                state new_state;
                new_state.dev = ++ sz;
                gen[i].lf_child = - new_state.dev;
                for (int cur : gen[i].fin)
                    new_state.fin.push_back(cur);
                new_gen.push_back(new_state);
                new_state = state();

                new_state.dev = ++ sz;
                gen[i].rf_child = - new_state.dev;
                for (int cur : gen[i].fin)
                    new_state.fin.push_back(cur + (1 << step));
                new_gen.push_back(new_state);
            }
            for (state cur : gen)
            {
                x.push_back(cur.lf_child);
                y.push_back(cur.rf_child);
            }
            gen = new_gen;
        }
        ///cout << "fine" << endl;
        int offset = gen.size() * 2 - g[v].size();
        for (int i = 0; i < gen.size(); i ++)
        {
            ///cout << gen[i].fin.size() << endl;
            int lf_path = gen[i].fin[0], rf_path = gen[i].fin[0] + (1 << st);
            ///cout << v << " :: " << lf_path << " : " << rf_path << endl;
            if (lf_path > offset)
                x.push_back(g[v][lf_path - offset - 1]);
            else
                x.push_back(- it.dev);
            if (rf_path > offset)
                y.push_back(g[v][rf_path - offset - 1]);
            else
                y.push_back(-it.dev);
        }
}
void create_circuit(int M, vector<int> A)
{
    n = A.size();
    m = M;

     c.resize(m + 1);
    g[0].push_back(A[0]);
    for (int i = 1; i < A.size(); i ++)
    {
        g[A[i - 1]].push_back(A[i]);
    }
    g[A.back()].push_back(0);
    for (int i = 0; i <= m; i ++)
    {
        create_node(i);
        continue;

    }
    /**for (int i = 0; i <= m; i ++)
        cout << c[i] << " ";
    cout << endl;
    for (int i = 0; i < x.size(); i ++)
        cout << x[i] << " " << y[i] << endl;*/
    answer(c, x, y);
}

Compilation message

doll.cpp: In function 'void create_node(int)':
doll.cpp:27:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   27 |     if (g[v].size() == 0)
      |     ^~
doll.cpp:30:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   30 |         if (g[v].size() == 1)
      |         ^~
doll.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         while(nec < g[v].size())
      |               ~~~~^~~~~~~~~~~~~
doll.cpp:49:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<state>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             for (int i = 0; i < gen.size(); i ++)
      |                             ~~^~~~~~~~~~~~
doll.cpp:74:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<state>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for (int i = 0; i < gen.size(); i ++)
      |                         ~~^~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:96:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for (int i = 1; i < A.size(); i ++)
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 27 ms 8660 KB Output is correct
3 Correct 22 ms 8344 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 14 ms 6100 KB Output is correct
6 Correct 33 ms 10076 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 27 ms 8660 KB Output is correct
3 Correct 22 ms 8344 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 14 ms 6100 KB Output is correct
6 Correct 33 ms 10076 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 47 ms 10576 KB Output is correct
9 Correct 51 ms 11000 KB Output is correct
10 Correct 76 ms 13424 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 27 ms 8660 KB Output is correct
3 Correct 22 ms 8344 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 14 ms 6100 KB Output is correct
6 Correct 33 ms 10076 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 47 ms 10576 KB Output is correct
9 Correct 51 ms 11000 KB Output is correct
10 Correct 76 ms 13424 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 101 ms 14936 KB Output is correct
15 Correct 57 ms 9896 KB Output is correct
16 Correct 79 ms 12560 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5000 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 87 ms 13996 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 4 ms 4948 KB Output is partially correct
2 Correct 61 ms 18616 KB Output is correct
3 Partially correct 106 ms 30564 KB Output is partially correct
4 Partially correct 113 ms 31492 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 4 ms 4948 KB Output is partially correct
2 Correct 61 ms 18616 KB Output is correct
3 Partially correct 106 ms 30564 KB Output is partially correct
4 Partially correct 113 ms 31492 KB Output is partially correct
5 Partially correct 128 ms 17084 KB Output is partially correct
6 Partially correct 132 ms 18152 KB Output is partially correct
7 Partially correct 127 ms 17724 KB Output is partially correct
8 Partially correct 145 ms 18740 KB Output is partially correct
9 Partially correct 104 ms 20072 KB Output is partially correct
10 Partially correct 144 ms 22600 KB Output is partially correct
11 Partially correct 152 ms 19400 KB Output is partially correct
12 Partially correct 101 ms 14356 KB Output is partially correct
13 Partially correct 88 ms 13636 KB Output is partially correct
14 Partially correct 91 ms 13292 KB Output is partially correct
15 Partially correct 84 ms 12852 KB Output is partially correct
16 Partially correct 5 ms 5204 KB Output is partially correct
17 Partially correct 80 ms 12232 KB Output is partially correct
18 Partially correct 89 ms 12300 KB Output is partially correct
19 Partially correct 86 ms 12776 KB Output is partially correct
20 Partially correct 109 ms 14968 KB Output is partially correct
21 Partially correct 133 ms 17128 KB Output is partially correct
22 Partially correct 108 ms 14252 KB Output is partially correct