Submission #316373

#TimeUsernameProblemLanguageResultExecution timeMemory
316373alextodoranMechanical Doll (IOI18_doll)C++17
Compilation error
0 ms0 KiB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>
#include "doll.h"

using namespace std;

typedef long long ll;

struct XYSwitch
{
    int X, Y;
    bool state;
};

vector <XYSwitch> switches;

int createInfiniteSwitch (int N, int firstPos, int level)

    if(level == 0)
    {
        if(N == 0)
        {
            int X = -777777777;
            int Y = -777777777;
            switches.push_back(XYSwitch{X, Y});
            return (int)switches.size() - 1;
        }
        if(N == 1)
        {
            int X = -firstPos;
            int Y = -777777777;
            switches.push_back(XYSwitch{X, Y});
            return (int)switches.size() - 1;
        }
        if(N == 2)
        {
            int X = -firstPos;
            int Y = -(firstPos + 1);
            switches.push_back(XYSwitch{X, Y});
            return (int)switches.size() - 1;
        }
    }
    int L;
    if(N > 0)
    {
        int p2 = 0;
        while((1 << (p2 + 1)) < N)
            p2++;
        L = (1 << p2);
    }
    else
        L = 0;
    int X = createInfiniteSwitch(L, firstPos, level - 1);
    int Y = createInfiniteSwitch(N - L, firstPos + L, level - 1);
    switches.push_back(XYSwitch{X, Y, false});
    return (int)switches.size() - 1;
}

int createFiniteSwitch (int N, int firstPos, int level)
{
    if(level == 0)
    {
        if(N == 0)
        {
            int X = -777777777;
            int Y = 0;
            switches.push_back(XYSwitch{X, Y, false});
            return (int)switches.size() - 1;
        }
        if(N == 1)
        {
            int X = -firstPos;
            int Y = 0;
            switches.push_back(XYSwitch{X, Y, false});
            return (int)switches.size() - 1;
        }
    }
    int L;
    if(N > 0)
    {
        int p2 = 0;
        while((1 << (p2 + 1)) < N)
            p2++;
        L = (1 << p2);
    }
    else
        L = 0;
    int X = createInfiniteSwitch(L, firstPos, level - 1);
    int Y = createFiniteSwitch(N - L, firstPos + L, level - 1);
    switches.push_back(XYSwitch{X, Y, false});
    return (int)switches.size() - 1;
}

vector <int> triggers;

int curr;

bool dfs (int u)
{
    if(u < 0)
    {
        triggers[-u] = curr;
        return true;
    }
    if(u == 0)
        return false;
    switches[u].state ^= 1;
    if(switches[u].state == true)
        return dfs(switches[u].X);
    else
        return dfs(switches[u].Y);
}

void create_circuit(int M, vector <int> A)
{
    int N = A.size();
    switches.clear();
    switches.push_back(XYSwitch{0, 0, false});
    int p2 = 0;
    while((1 << (p2 + 1)) <= N)
        p2++;
    int root = createFiniteSwitch(N, 1, p2 - 1);
    for(int i = 1; i < (int)switches.size(); i++)
    {
        if(switches[i].X == -777777777)
            switches[i].X = root;
        if(switches[i].Y == -777777777)
            switches[i].Y = root;
    }
    triggers.clear();
    triggers.resize(M + 1);
    for(int i = 0; i < N; i++)
    {
        curr = A[i];
        while(true)
        {
            if(dfs(root) == true)
                break;
        }
    }
    vector <int> X(switches.size() - 1), Y(switches.size() - 1), C(M + 1);
    for(int i = 1; i < (int)switches.size(); i++)
    {
        if(switches[i].X < 0)
            X[i - 1] = triggers[-switches[i].X];
        else
            X[i - 1] = -switches[i].X;
        if(switches[i].Y < 0)
            Y[i - 1] = triggers[-switches[i].Y];
        else
            Y[i - 1] = -switches[i].Y;
    }
    C[0] = -root;
    for(int i = 1; i <= M; i++)
        C[i] = root;
    answer(C, X, Y);
}

Compilation message (stderr)

doll.cpp:26:5: error: expected initializer before 'if'
   26 |     if(level == 0)
      |     ^~
doll.cpp:51:5: error: expected unqualified-id before 'if'
   51 |     if(N > 0)
      |     ^~
doll.cpp:58:5: error: expected unqualified-id before 'else'
   58 |     else
      |     ^~~~
doll.cpp:60:37: error: 'firstPos' was not declared in this scope
   60 |     int X = createInfiniteSwitch(L, firstPos, level - 1);
      |                                     ^~~~~~~~
doll.cpp:60:47: error: 'level' was not declared in this scope
   60 |     int X = createInfiniteSwitch(L, firstPos, level - 1);
      |                                               ^~~~~
doll.cpp:60:13: error: 'createInfiniteSwitch' was not declared in this scope
   60 |     int X = createInfiniteSwitch(L, firstPos, level - 1);
      |             ^~~~~~~~~~~~~~~~~~~~
doll.cpp:61:34: error: 'N' was not declared in this scope
   61 |     int Y = createInfiniteSwitch(N - L, firstPos + L, level - 1);
      |                                  ^
doll.cpp:61:41: error: 'firstPos' was not declared in this scope
   61 |     int Y = createInfiniteSwitch(N - L, firstPos + L, level - 1);
      |                                         ^~~~~~~~
doll.cpp:61:55: error: 'level' was not declared in this scope
   61 |     int Y = createInfiniteSwitch(N - L, firstPos + L, level - 1);
      |                                                       ^~~~~
doll.cpp:61:13: error: 'createInfiniteSwitch' was not declared in this scope
   61 |     int Y = createInfiniteSwitch(N - L, firstPos + L, level - 1);
      |             ^~~~~~~~~~~~~~~~~~~~
doll.cpp:62:5: error: 'switches' does not name a type
   62 |     switches.push_back(XYSwitch{X, Y, false});
      |     ^~~~~~~~
doll.cpp:62:45: error: expected unqualified-id before ')' token
   62 |     switches.push_back(XYSwitch{X, Y, false});
      |                                             ^
doll.cpp:63:5: error: expected unqualified-id before 'return'
   63 |     return (int)switches.size() - 1;
      |     ^~~~~~
doll.cpp:64:1: error: expected declaration before '}' token
   64 | }
      | ^
doll.cpp: In function 'int createFiniteSwitch(int, int, int)':
doll.cpp:95:13: error: 'createInfiniteSwitch' was not declared in this scope; did you mean 'createFiniteSwitch'?
   95 |     int X = createInfiniteSwitch(L, firstPos, level - 1);
      |             ^~~~~~~~~~~~~~~~~~~~
      |             createFiniteSwitch