Submission #1016648

# Submission time Handle Problem Language Result Execution time Memory
1016648 2024-07-08T09:50:41 Z Unforgettablepl Mechanical Doll (IOI18_doll) C++17
75.4031 / 100
113 ms 12900 KB
#include <bits/stdc++.h>
using namespace std;

void answer(vector<int> C, vector<int> X, vector<int> Y);

int reverse_bits(int x){
    int res = 0;
    for(int bit=0;bit<=18;bit++)if(x&bit)res|=1<<(30-bit);
    return res;
}

void create_circuit(int M, vector<int> A) {    
    int N = A.size();
    vector<int> C(M + 1,-1);C[0]=A[0];
    vector<int> X(400001),Y(400001);
    vector<int> nextoccurences = A;
    nextoccurences.erase(nextoccurences.begin());
    nextoccurences.emplace_back(0);
    vector<int> perm;
    {
        vector<pair<int,int>> elements;
        int siz = 2;
        while(nextoccurences.size()>siz)siz<<=1;
        int tar = siz-N;
        vector<bool> taken(siz);
        for(int i=0;i<siz;i++)elements.emplace_back(reverse_bits(i),i);
        sort(elements.begin(),elements.end());
        for(int i=0;i<tar;i++)taken[elements[i].second]=true;
        auto iter = nextoccurences.begin();
        for(int i=0;i<siz;i++){
            if(taken[i])perm.emplace_back(-1);
            else perm.emplace_back(*(iter++));
        }
    }
    int S = 1;
    function<void(int,vector<int>)> calc = [&](int x,vector<int> targets){
        if(targets.size()==2){
            X[x] = targets[0];
            Y[x] = targets[1];
        } else {
            vector<int> odds;
            vector<int> evens;
            for(int i=0;i<targets.size();i++)
                if(i&1)odds.emplace_back(targets[i]);
                else evens.emplace_back(targets[i]);
            bool Xworks = false;
            for(int&i:evens)if(i!=-1)Xworks=true;
            bool Yworks = false;
            for(int&i:odds)if(i!=-1)Yworks=true;
            if(Xworks){
                X[x] = -(++S);
                calc(S,evens);
            } else {
                X[x] = -1;
            }
            if(Yworks){
                Y[x] = -(++S);
                calc(S,odds);
            } else {
                Y[x] = -1;
            }
        }
    };
    calc(1,perm);
    X.erase(X.begin());
    Y.erase(Y.begin());
    X.resize(S);
    Y.resize(S);
    answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:23:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |         while(nextoccurences.size()>siz)siz<<=1;
      |               ~~~~~~~~~~~~~~~~~~~~~^~~~
doll.cpp: In lambda function:
doll.cpp:43:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             for(int i=0;i<targets.size();i++)
      |                         ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 31 ms 7716 KB Output is correct
3 Correct 35 ms 7616 KB Output is correct
4 Correct 2 ms 3416 KB Output is correct
5 Correct 7 ms 4532 KB Output is correct
6 Incorrect 48 ms 9164 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 31 ms 7716 KB Output is correct
3 Correct 35 ms 7616 KB Output is correct
4 Correct 2 ms 3416 KB Output is correct
5 Correct 7 ms 4532 KB Output is correct
6 Incorrect 48 ms 9164 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 31 ms 7716 KB Output is correct
3 Correct 35 ms 7616 KB Output is correct
4 Correct 2 ms 3416 KB Output is correct
5 Correct 7 ms 4532 KB Output is correct
6 Incorrect 48 ms 9164 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
3 Correct 2 ms 3416 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
8 Correct 3 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 48 ms 9504 KB Output is correct
3 Correct 62 ms 11076 KB Output is correct
4 Partially correct 113 ms 12312 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 48 ms 9504 KB Output is correct
3 Correct 62 ms 11076 KB Output is correct
4 Partially correct 113 ms 12312 KB Output is partially correct
5 Partially correct 87 ms 12480 KB Output is partially correct
6 Partially correct 83 ms 12492 KB Output is partially correct
7 Partially correct 84 ms 12900 KB Output is partially correct
8 Partially correct 83 ms 12480 KB Output is partially correct
9 Partially correct 63 ms 10944 KB Output is partially correct
10 Partially correct 84 ms 12488 KB Output is partially correct
11 Partially correct 81 ms 12424 KB Output is partially correct
12 Correct 63 ms 10944 KB Output is correct
13 Correct 50 ms 9664 KB Output is correct
14 Correct 68 ms 11200 KB Output is correct
15 Correct 66 ms 11200 KB Output is correct
16 Correct 3 ms 3676 KB Output is correct
17 Correct 50 ms 9632 KB Output is correct
18 Correct 54 ms 9412 KB Output is correct
19 Correct 64 ms 11144 KB Output is correct
20 Partially correct 82 ms 12476 KB Output is partially correct
21 Partially correct 90 ms 12488 KB Output is partially correct
22 Partially correct 102 ms 12480 KB Output is partially correct