Submission #775636

#TimeUsernameProblemLanguageResultExecution timeMemory
775636GusterGoose27자동 인형 (IOI18_doll)C++17
84 / 100
123 ms262144 KiB
#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;
    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 (stderr)

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:70:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   70 |     while (f < n) f *= 2; t++;
      |     ^~~~~
doll.cpp:70:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   70 |     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:72:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     state = vector<int>(t); assert(t == x.size()+1);
      |                                    ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...