Submission #1024761

# Submission time Handle Problem Language Result Execution time Memory
1024761 2024-07-16T10:05:48 Z Zicrus Mechanical Doll (IOI18_doll) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
 
typedef long long ll;
 
vector<int> C, X, Y, state;
 
int connect(int a, int bSize, int b, int orig = 0, int mask = 0, int bit = 0) {
    if (!bit && orig) return b;
    
    X.push_back(0);
    Y.push_back(0);
    int id = X.size() - 1;
    bool first = false;
    if (!orig) {
        first = true;
        orig = -X.size();
        mask = bSize - 1;
        if (mask == 0) {
            X.pop_back();
            Y.pop_back();
            return b;
        }
        bit = 1 << (int)log2(mask);
    }
 
    if (mask & bit) {
        X[id] = connect(a, bSize - (1 << ((int)log2(bSize) - 1)), b, orig, mask, bit >> 1);
        Y[id] = connect(a, 1 << ((int)log2(bSize) - 1), b, orig, ~0, bit >> 1);
    }
    else {
        X[id] = orig;
        Y[id] = connect(a, 1 << ((int)log2(bSize) - 1), b, orig, mask, bit >> 1);
    }
 
    if (first) {
        Y[X.size() - 1] = 0;
    }
 
    return -id - 1;
}
 
void create_circuit(int M, vector<int> A) {
    C = vector<int>(M + 1);
    X = vector<int>(); Y = vector<int>();
    vector<vector<int>> adj(M + 1);
    int prev = 0;
    for(auto &e : A) {
        adj[prev].push_back(e);
        prev = e;
    }
    C[0] = connect(i, A.size(), 1);
    for (int i = 1; i < adj.size(); i++) {
        C[i] = C[0];
    }
 
    state = vector<int>(X.size());
    int pos = 0;
    for (int i = 0; i < A.size(); i++) {
        int prev = pos;
        do {
            prev = pos;
            if (pos >= 0) {
                pos = C[pos];
            }
            else {
                pos = state[-pos - 1] ? Y[-pos - 1] : X[-pos - 1];
                state[-prev - 1] = !state[-prev - 1];
            }
        } while (pos < 0);
        if (pos != A[i]) {
            (!state[-prev - 1] ? Y[-prev - 1] : X[-prev - 1]) = A[i];
            pos = A[i];
        }
    }
 
    answer(C, X, Y);
    return;
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:53:20: error: 'i' was not declared in this scope
   53 |     C[0] = connect(i, A.size(), 1);
      |                    ^
doll.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 1; i < adj.size(); i++) {
      |                     ~~^~~~~~~~~~~~
doll.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < A.size(); i++) {
      |                     ~~^~~~~~~~~~