Submission #775639

# Submission time Handle Problem Language Result Execution time Memory
775639 2023-07-06T16:44:11 Z GusterGoose27 Mechanical Doll (IOI18_doll) C++17
100 / 100
107 ms 10708 KB
#include "doll.h"

#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> x, y;

int t = 0;

void make(int n, int f) {
    if (f == 2) {
        if (n == 2) {
            x.push_back(0);
            y.push_back(0);
        }
        else {
            x.push_back(-1);
            y.push_back(0);
        }
        t++;
        return;
    }
    if (n <= f/2) {
        x.push_back(-1);
        t++;
        y.push_back(-t);
        make(n, f/2);
    }
    else {
        t++;
        int l_size = n-f/2;
        x.push_back(-t);
        y.push_back(0);
        int uv = y.size()-1;
        make(l_size, f/2);
        y[uv] = -t;
        make(f/2, f/2);
    }
    return;
}

vector<int> state;

void sim(int cur, int tar) {
    int nxt;
    if (state[cur] == 0) {
        nxt = -x[cur-1];
    }
    else nxt = -y[cur-1];
    if (nxt == 0) {
        if (state[cur] == 0) x[cur-1] = tar;
        else y[cur-1] = tar;
    }
    state[cur] = 1-state[cur];
    if (nxt != 0) sim(nxt, tar);
}

void create_circuit(int M, vector<int> A) {
    n = A.size();
    m = M;
    if (n == 1) {
        vector<int> x, y;
        vector<int> C(M + 1);
        fill(C.begin(), C.end(), 0);
        C[0] = A[0];
        return answer(C, x, y);
    }
    vector<int> C(M + 1);
    fill(C.begin(), C.end(), -1);
    C[0] = A[0];
    vector<int> nvals;
    for (int i = 1; i < n; i++) nvals.push_back(A[i]);
    nvals.push_back(0);
    int f = 1;
    while (f < n) f *= 2; t++;
    make(n, f);
    state = vector<int>(t); assert(t == x.size()+1);
    fill(state.begin(), state.end(), 0);
    for (int i = 0; i < n; i++) sim(1, nvals[i]);
    answer(C, x, y);
    // for (int i = 0; i < x.size(); i++) cout << x[i] << ' ' << y[i] << "\n";
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:77:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   77 |     while (f < n) f *= 2; t++;
      |     ^~~~~
doll.cpp:77:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   77 |     while (f < n) f *= 2; t++;
      |                           ^
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from doll.cpp:3:
doll.cpp:79:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     state = vector<int>(t); assert(t == x.size()+1);
      |                                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 37 ms 4300 KB Output is correct
3 Correct 29 ms 4352 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 8 ms 1452 KB Output is correct
6 Correct 45 ms 5744 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 37 ms 4300 KB Output is correct
3 Correct 29 ms 4352 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 8 ms 1452 KB Output is correct
6 Correct 45 ms 5744 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 53 ms 7088 KB Output is correct
9 Correct 59 ms 8052 KB Output is correct
10 Correct 107 ms 10708 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 37 ms 4300 KB Output is correct
3 Correct 29 ms 4352 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 8 ms 1452 KB Output is correct
6 Correct 45 ms 5744 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 53 ms 7088 KB Output is correct
9 Correct 59 ms 8052 KB Output is correct
10 Correct 107 ms 10708 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 224 KB Output is correct
14 Correct 88 ms 10388 KB Output is correct
15 Correct 54 ms 7276 KB Output is correct
16 Correct 89 ms 10172 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 88 ms 10496 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 50 ms 5788 KB Output is correct
3 Correct 56 ms 5584 KB Output is correct
4 Correct 81 ms 8212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 50 ms 5788 KB Output is correct
3 Correct 56 ms 5584 KB Output is correct
4 Correct 81 ms 8212 KB Output is correct
5 Correct 86 ms 8488 KB Output is correct
6 Correct 87 ms 8292 KB Output is correct
7 Correct 85 ms 8456 KB Output is correct
8 Correct 94 ms 8256 KB Output is correct
9 Correct 52 ms 5492 KB Output is correct
10 Correct 87 ms 8248 KB Output is correct
11 Correct 83 ms 8220 KB Output is correct
12 Correct 52 ms 5852 KB Output is correct
13 Correct 51 ms 5832 KB Output is correct
14 Correct 57 ms 6300 KB Output is correct
15 Correct 54 ms 6448 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 50 ms 5796 KB Output is correct
18 Correct 54 ms 5784 KB Output is correct
19 Correct 53 ms 5868 KB Output is correct
20 Correct 81 ms 8216 KB Output is correct
21 Correct 82 ms 8224 KB Output is correct
22 Correct 83 ms 8208 KB Output is correct