Submission #817008

# Submission time Handle Problem Language Result Execution time Memory
817008 2023-08-09T08:25:27 Z Jarif_Rahman Mechanical Doll (IOI18_doll) C++17
84 / 100
70 ms 10820 KB
#include "doll.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

const int inf = 1e7;

void create_circuit(int m, vector<int> A){
    int n = A.size();
    int k = 1;
    while(k < n) k*=2;

    vector<int> sth(2*k, -2);
    vector<pair<int, int>> candidates;
    for(int i = k; i < 2*k; i++){
        int j = i, pos = 0;
        while(j != 1){
            if(j&1) pos++;
            pos<<=1;
            j>>=1;
        }
        pos>>=1;
        if(2*k-i-1 < n) candidates.pb({pos, i});
        sth[i] = -1;
    }

    sort(candidates.begin(), candidates.end());
    for(int i = 1; i < n; i++) sth[candidates[i-1].sc] = A[i];
    sth[candidates.back().sc] = 0;

    vector<int> C(m+1, -1), X, Y;
    C[0] = A[0];

    for(int i = k-1; i >= 1; i--){
        if(sth[2*i] == -1 && sth[2*i+1] == -1) sth[i] = -1;
    }

    function<int(int)> rec = [&](int i){
        X.pb(0), Y.pb(0);
        int j = X.size();

        if(sth[2*i] == -1) X[j-1] = -1;
        else if(sth[2*i] >= 0) X[j-1] = sth[2*i];
        else X[j-1] = rec(2*i);

        if(sth[2*i+1] == -1) Y[j-1] = -1;
        else if(sth[2*i+1] >= 0) Y[j-1] = sth[2*i+1];
        else Y[j-1] = rec(2*i+1);

        return -j;
    };

    rec(1);

    answer(C, X, Y);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 26 ms 4984 KB Output is correct
3 Correct 25 ms 5440 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 39 ms 7568 KB Output is correct
7 Incorrect 0 ms 212 KB state 'Y'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 26 ms 4984 KB Output is correct
3 Correct 25 ms 5440 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 39 ms 7568 KB Output is correct
7 Incorrect 0 ms 212 KB state 'Y'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 26 ms 4984 KB Output is correct
3 Correct 25 ms 5440 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 39 ms 7568 KB Output is correct
7 Incorrect 0 ms 212 KB state 'Y'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 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 Correct 1 ms 212 KB Output is correct
2 Correct 38 ms 6728 KB Output is correct
3 Correct 50 ms 7836 KB Output is correct
4 Correct 63 ms 10664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 38 ms 6728 KB Output is correct
3 Correct 50 ms 7836 KB Output is correct
4 Correct 63 ms 10664 KB Output is correct
5 Correct 67 ms 10812 KB Output is correct
6 Correct 70 ms 10748 KB Output is correct
7 Correct 68 ms 10820 KB Output is correct
8 Correct 66 ms 10736 KB Output is correct
9 Correct 40 ms 7756 KB Output is correct
10 Correct 66 ms 10800 KB Output is correct
11 Correct 64 ms 10744 KB Output is correct
12 Correct 41 ms 7808 KB Output is correct
13 Correct 40 ms 6860 KB Output is correct
14 Correct 46 ms 7876 KB Output is correct
15 Correct 43 ms 7912 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 40 ms 6724 KB Output is correct
18 Correct 39 ms 6748 KB Output is correct
19 Correct 41 ms 7840 KB Output is correct
20 Correct 67 ms 10728 KB Output is correct
21 Correct 69 ms 10672 KB Output is correct
22 Correct 63 ms 10700 KB Output is correct