Submission #1244865

#TimeUsernameProblemLanguageResultExecution timeMemory
1244865j_vdd16Mechanical Doll (IOI18_doll)C++20
0 / 100
0 ms324 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

#include "doll.h"

using namespace std;

#define loop(X, N) for (int X = 0; X < (N); X++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;

int numBits = 0;
int rev(int n) {
    int out = 0;
    for (int i = 0; i < numBits; i++) {
        if (n & (1 << i))
            out |= 1 << (numBits - 1 - i);
    }

    return out;
}

bool cmp(int a, int b) {
    return rev(a) < rev(b);
}

void create_circuit(int m, vi a) {
    vi c; //exits
    vi x, y;

    int n = a.size();
    c.push_back(a[0]);
    
    int pow = 1;
    while (pow < n) {
        numBits++;
        pow *= 2;
    }

    vi order(pow);
    for (int i = 0; i < pow; i++) {
        order[i] = i;
    }

    sort(order.begin(), order.end(), cmp);

    if (pow == 1) {
        c.push_back(0);
    }
    else {
        vi exits(pow);
        for (int j = 0; j < n - 1; j++) {
            exits[order[j]] = a[j + 1];
        }
        for (int j = n - 1; j < pow - 1; j++) {
            exits[order[j]] = -1;
        }
        exits[order[pow - 1]] = 0;

        for (int j = 1; j < pow / 2; j++) {
            x.push_back(-2 * j);
            y.push_back(-2 * j - 1);
        }
        for (int j = 0; j < pow / 2; j++) {
            x.push_back(exits[j * 2]);
            y.push_back(exits[j * 2 + 1]);
        }

        for (int i = 0; i < n; i++)
            c.push_back(-1);
    }
    
    answer(c, x, y);
}
#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...