Submission #613931

# Submission time Handle Problem Language Result Execution time Memory
613931 2022-07-30T13:33:44 Z fvogel499 Mechanical Doll (IOI18_doll) C++17
70.6719 / 100
298 ms 31104 KB
#include "doll.h"
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define vi vector<int>

void create_circuit(int nbT, std::vector<int> b) {
    vi tOut(nbT+1, -1);
    int p2 = 1;
    while (p2*2 <= sz(b)) p2 *= 2;
    vi xSw(2*p2-1);
    vi ySw(2*p2-1);
    for (int i = 0; i < p2-1; i++) {
        assert(0 <= i && i < 2*p2-1);
        xSw[i] = 2*i+1;
        ySw[i] = 2*i+2;
    }
    for (int i = p2-1; i < 2*p2-1; i++) {
        assert(0 <= i && i < 2*p2-1);
        xSw[i] = ySw[i] = 0;
    }
    vi ptr(2*p2-1);
    for (int i = 0; i < p2/2; i++) ptr[i] = 0;
    vector<pair<int, int>> to;
    assert(sz(b) <= p2*2-1);
    for (int i = 0; i < p2*2-1; i++) {
        int x = 0;
        while (x < p2-1) {
            assert(0 <= i && i < 2*p2-1);
            ptr[x] ^= 1;
            if (ptr[x] == 1) {
                x = xSw[x];
            }
            else {
                x = ySw[x];
            }
        }
        assert(0 <= x && x < 2*p2-1);
        to.pb({x, ptr[x]});
        ptr[x] ^= 1;
    }
    int lenSeg = (sz(b)+1)/2;
    int startPos = p2-1;
    int endPos = startPos+lenSeg-1;
    int curToIdx = 0;
    bool used [2*p2-1];
    for (int i = 0; i < 2*p2-1; i++) {
        used[i] = false;
    }
    int otherPurposeX = 2*p2-2;
    while (otherPurposeX >= 0) {
        used[otherPurposeX] = true;
        if (otherPurposeX == 0) break;
        otherPurposeX = (otherPurposeX-1)/2;
    }
    for (int i : b) {
        while (curToIdx < sz(to) && !(startPos <= to[curToIdx].first && to[curToIdx].first <= endPos)) {
            curToIdx++;
        }
        assert(curToIdx < sz(to));
        if (to[curToIdx].second == 0) {
            xSw[to[curToIdx].first] = -i;
        }
        else {
            ySw[to[curToIdx].first] = -i;
        }
        int x = to[curToIdx].first;
        while (x >= 0) {
            used[x] = true;
            if (x == 0) break;
            x = (x-1)/2;
        }
        curToIdx++;
    }
    set<int> usedSet;
    for (int i = 0; i < 2*p2-1; i++) if (used[i]) usedSet.insert(i);
    map<int, int> usedCompress;
    int kc2 = 0;
    for (int i : usedSet) {
        usedCompress[i] = kc2;
        kc2++;
    }
    vector<int> swCompX(sz(usedSet)), swCompY(sz(usedSet));
    for (int i = 0; i < 2*p2-1; i++) if (used[i]) {
        int iComp = usedCompress[i];
        int xVal = xSw[i];
        int yVal = ySw[i];
        if (usedSet.count(xVal)) {
            swCompX[iComp] = usedCompress[xVal];
        }
        else if (xVal < 0) {
            swCompX[iComp] = xVal;
        }
        else {
            swCompX[iComp] = 0;
        }
        if (usedSet.count(yVal)) {
            swCompY[iComp] = usedCompress[yVal];
        }
        else if (yVal < 0) {
            swCompY[iComp] = yVal;
        }
        else {
            swCompY[iComp] = 0;
        }
    }
    for (int i = 0; i < sz(swCompX); i++) {
        if (swCompX[i] < 0) {
            swCompX[i] *= -1;
        }
        else {
            swCompX[i] = -1-swCompX[i];
        }
        if (swCompY[i] < 0) {
            swCompY[i] *= -1;
        }
        else {
            swCompY[i] = -1-swCompY[i];
        }
    }
    swCompY[usedCompress[2*p2-2]] = 0;
    answer(tOut, swCompX, swCompY);
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 300 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 196 ms 22120 KB Output is correct
3 Partially correct 183 ms 22116 KB Output is partially correct
4 Partially correct 258 ms 30688 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 196 ms 22120 KB Output is correct
3 Partially correct 183 ms 22116 KB Output is partially correct
4 Partially correct 258 ms 30688 KB Output is partially correct
5 Partially correct 298 ms 31104 KB Output is partially correct
6 Partially correct 258 ms 30916 KB Output is partially correct
7 Partially correct 272 ms 31000 KB Output is partially correct
8 Partially correct 258 ms 30860 KB Output is partially correct
9 Partially correct 199 ms 22208 KB Output is partially correct
10 Partially correct 267 ms 30728 KB Output is partially correct
11 Partially correct 264 ms 30688 KB Output is partially correct
12 Partially correct 197 ms 22076 KB Output is partially correct
13 Correct 191 ms 22248 KB Output is correct
14 Partially correct 190 ms 22452 KB Output is partially correct
15 Partially correct 185 ms 22392 KB Output is partially correct
16 Partially correct 4 ms 980 KB Output is partially correct
17 Correct 155 ms 19364 KB Output is correct
18 Correct 188 ms 22004 KB Output is correct
19 Partially correct 180 ms 22076 KB Output is partially correct
20 Partially correct 261 ms 30700 KB Output is partially correct
21 Partially correct 262 ms 30648 KB Output is partially correct
22 Partially correct 280 ms 30672 KB Output is partially correct