Submission #464996

# Submission time Handle Problem Language Result Execution time Memory
464996 2021-08-14T20:13:19 Z blue Mechanical Doll (IOI18_doll) C++17
100 / 100
237 ms 13016 KB
#include "doll.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;

int N;
int k;

const int rt = 1e9;

vector<int> I;

void create_circuit(int M, vector<int> A)
{
    N = A.size();
    if(A.size() == 1)
    {
        vector<int> C(M+1, 0);
        C[0] = A[0];
        vector<int> X(0), Y(0);
        answer(C, X, Y);
        return;
    }

    // assert(A.size() > 1);


    for(k = 0; (1 << k) < N; k++); //2^k >= N

    I = vector<int>( (1 << k) );
    for(int i = 0; i < (1 << k); i++)
        I[i] = i;

    sort(I.begin(), I.end(), [] (int p, int q)
    {
        for(int y = 0; y < k; y++)
        {
            if((p & (1 << y)) < (q & (1 << y)))
                return 1;
            else if((q & (1 << y)) < (p & (1 << y)))
                return 0;
        }
        return 0;
    });

    // for(int i:I) cerr << i << ' ';
    // cerr << '\n';

    vector<int> J(N);
    for(int i = 0; i < N; i++) J[i] = I.size() - N + i;
    sort(J.begin(), J.end(), [] (int x, int y)
    {
        return I[x] < I[y];
    });



    vector<int> A1[k+1];

    A1[k] = vector<int>((1 << k), rt);

    for(int i = 1; i < N; i++)
        A1[k][ J[i-1] ] = A[i];

    A1[k][J[N-1]] = 0;


    int S = 0;
    vector<int> C(M+1);
    vector<int> X;
    vector<int> Y;
    for(int l = k-1; l >= 0; l--)
    {
        for(int i = 0; i < (1 << l); i++)
        {
            if(A1[l+1][2*i] == A1[l+1][2*i+1])
                A1[l].push_back(A1[l+1][2*i]);
            else
            {
                S++;
                A1[l].push_back(-S);
                X.push_back(A1[l+1][2*i]);
                Y.push_back(A1[l+1][2*i+1]);
            }
        }
    }
    C[0] = A[0];
    for(int i = 1; i <= M; i++)
        C[i] = -S;

    for(int j = 1; j <= S; j++)
    {
        if(X[j-1] == rt)
            X[j-1] = -S;
        if(Y[j-1] == rt)
            Y[j-1] = -S;
    }




    // for(int l = 0; l <= k; l++)
    // {
    //     for(int i = 0; i < (1 << l); i++) cerr << A1[l][i] << ' ';
    //     cerr << '\n';
    // }

    // cerr << "S = " << S << '\n';

    answer(C, X, Y);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 68 ms 4652 KB Output is correct
3 Correct 97 ms 4944 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 12 ms 1356 KB Output is correct
6 Correct 116 ms 6440 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 68 ms 4652 KB Output is correct
3 Correct 97 ms 4944 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 12 ms 1356 KB Output is correct
6 Correct 116 ms 6440 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 125 ms 8140 KB Output is correct
9 Correct 205 ms 10168 KB Output is correct
10 Correct 228 ms 13016 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 68 ms 4652 KB Output is correct
3 Correct 97 ms 4944 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 12 ms 1356 KB Output is correct
6 Correct 116 ms 6440 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 125 ms 8140 KB Output is correct
9 Correct 205 ms 10168 KB Output is correct
10 Correct 228 ms 13016 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 226 ms 12680 KB Output is correct
15 Correct 186 ms 9656 KB Output is correct
16 Correct 223 ms 12472 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 229 ms 12808 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 94 ms 3324 KB Output is correct
3 Correct 160 ms 4892 KB Output is correct
4 Correct 179 ms 5692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 94 ms 3324 KB Output is correct
3 Correct 160 ms 4892 KB Output is correct
4 Correct 179 ms 5692 KB Output is correct
5 Correct 221 ms 10824 KB Output is correct
6 Correct 223 ms 10576 KB Output is correct
7 Correct 237 ms 10832 KB Output is correct
8 Correct 234 ms 10712 KB Output is correct
9 Correct 174 ms 7456 KB Output is correct
10 Correct 211 ms 10420 KB Output is correct
11 Correct 219 ms 10324 KB Output is correct
12 Correct 180 ms 7980 KB Output is correct
13 Correct 116 ms 6552 KB Output is correct
14 Correct 198 ms 8608 KB Output is correct
15 Correct 184 ms 8632 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 114 ms 6424 KB Output is correct
18 Correct 114 ms 6428 KB Output is correct
19 Correct 185 ms 7964 KB Output is correct
20 Correct 216 ms 10456 KB Output is correct
21 Correct 218 ms 10444 KB Output is correct
22 Correct 215 ms 10456 KB Output is correct