Submission #254873

# Submission time Handle Problem Language Result Execution time Memory
254873 2020-07-30T19:02:37 Z emil_physmath Mechanical Doll (IOI18_doll) C++17
100 / 100
156 ms 11896 KB
#include "doll.h"
#include <iostream>
using namespace std;
#define BUGO(x) cerr << #x << ": " << x << '\n';

int n, N;
vector<int> a;
int nodes;
vector<int> c, x, y, state;

int Solve(int l, int r)
{
    static int nodes = 0;
    if (r < N - n + 1 || l == r)
        return -1;
    int v = nodes++;
    x.resize(nodes); y.resize(nodes); state.resize(nodes);
    int m = (l + r) / 2;
    x[v] = -Solve(l, m) - 1;
    if (!x[v]) x[v] = -1;
    y[v] = -Solve(m + 1, r) - 1;
    if (!y[v]) y[v] = -1;
    return v;
}
void DFS(int v, int l, int r)
{
    static int trigger = 0;
    // cerr << " -> " << -v-1;
    if (v == 0 && (l != 1 || r != N))
        return;
    int m = (l + r) / 2;
    if (!state[v]) {
        state[v] = 1;
        if (l == m && l >= N - n + 1)
            x[v] = a[trigger++];
        else
            DFS(-x[v]-1, l, m);
    }
    else {
        state[v] = 0;
        if (m + 1 == r && r >= N - n + 1)
            y[v] = a[trigger++];
        else
            DFS(-y[v]-1, m + 1, r);
    }
}
void create_circuit(int M, std::vector<int> a_) {
    a = a_;
    a.push_back(0);
    n = a.size();
    N = 1;
    while (N < n)
        N *= 2;
    Solve(1, N);
    for (int i = 0; i < N; ++i)
        DFS(0, 1, N);
        // cerr << "DFS", DFS(0, 1, N), cerr << '\n';
    c.resize(M + 1);
    for (int i = 0; i <= M; ++i)
        c[i] = -1;
    answer(c, x, y);
}
/*
5 10
2 3 4 2 1 4 3 2 3 2
3 6
2 3 3 2 1 2
3 4
2 2 3 3
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 55 ms 4532 KB Output is correct
3 Correct 54 ms 4316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 1388 KB Output is correct
6 Correct 70 ms 6732 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 55 ms 4532 KB Output is correct
3 Correct 54 ms 4316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 1388 KB Output is correct
6 Correct 70 ms 6732 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 102 ms 7588 KB Output is correct
9 Correct 114 ms 8000 KB Output is correct
10 Correct 142 ms 11896 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 55 ms 4532 KB Output is correct
3 Correct 54 ms 4316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 1388 KB Output is correct
6 Correct 70 ms 6732 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 102 ms 7588 KB Output is correct
9 Correct 114 ms 8000 KB Output is correct
10 Correct 142 ms 11896 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 156 ms 11368 KB Output is correct
15 Correct 102 ms 7088 KB Output is correct
16 Correct 137 ms 10988 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 140 ms 11396 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 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 Correct 1 ms 204 KB Output is correct
2 Correct 95 ms 6076 KB Output is correct
3 Correct 98 ms 6084 KB Output is correct
4 Correct 123 ms 9692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 95 ms 6076 KB Output is correct
3 Correct 98 ms 6084 KB Output is correct
4 Correct 123 ms 9692 KB Output is correct
5 Correct 139 ms 10892 KB Output is correct
6 Correct 132 ms 10532 KB Output is correct
7 Correct 149 ms 10520 KB Output is correct
8 Correct 131 ms 10268 KB Output is correct
9 Correct 89 ms 6080 KB Output is correct
10 Correct 141 ms 10216 KB Output is correct
11 Correct 132 ms 10020 KB Output is correct
12 Correct 90 ms 6332 KB Output is correct
13 Correct 93 ms 6672 KB Output is correct
14 Correct 104 ms 6812 KB Output is correct
15 Correct 100 ms 6944 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 79 ms 6828 KB Output is correct
18 Correct 99 ms 6300 KB Output is correct
19 Correct 98 ms 6304 KB Output is correct
20 Correct 155 ms 10252 KB Output is correct
21 Correct 150 ms 10004 KB Output is correct
22 Correct 127 ms 10008 KB Output is correct