Submission #1039464

# Submission time Handle Problem Language Result Execution time Memory
1039464 2024-07-30T23:37:21 Z boyliguanhan Mechanical Doll (IOI18_doll) C++17
100 / 100
62 ms 11104 KB
#include "doll.h"
using namespace std;
int unneeded,CC,mp[1<<18];
vector<int>a,b;
int create(int l,int r){
    if(unneeded>r-l)
        return unneeded-=r-l+1,-1;
    if(l==r) return l;
    int k=--CC;
    a.push_back(0);
    b.push_back(0);
    a[-k-1]=create(l,l+r>>1);
    b[-k-1]=create(l+r+2>>1,r);
    return k;
}
vector<int> a_order(int n,int sz,bool ok=1){
    if(n==-1&&ok) return vector<int>(sz,-1);
    if(n>0) return {n};
    vector<int>A=a_order(a[-n-1],sz/2),B=a_order(b[-n-1],sz/2),C;
    for(int i=0;i<A.size();i++)
        C.push_back(A[i]),C.push_back(B[i]);
    return C;
}
void create_circuit(int M, vector<int> A) {
    A.push_back(0);
    int N = A.size(),c=0;
    int k=1<<31-__builtin_clz(2*N-1);
    unneeded=k-N;
    vector<int>C(M+1,-1),s=a_order(create(1,k),k,0);
    for(auto i:s)
        if(i>0)
            mp[i]=A[c++];
    for(auto &i:a)
        if(i>0)i=mp[i];
    for(auto &i:b)
        if(i>0)i=mp[i];
    answer(C,a,b);
}

Compilation message

doll.cpp: In function 'int create(int, int)':
doll.cpp:12:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   12 |     a[-k-1]=create(l,l+r>>1);
      |                      ~^~
doll.cpp:13:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |     b[-k-1]=create(l+r+2>>1,r);
      |                    ~~~^~
doll.cpp: In function 'std::vector<int> a_order(int, int, bool)':
doll.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0;i<A.size();i++)
      |                 ~^~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:27:16: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   27 |     int k=1<<31-__builtin_clz(2*N-1);
      |              ~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 22 ms 4792 KB Output is correct
3 Correct 22 ms 4688 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 5 ms 1372 KB Output is correct
6 Correct 31 ms 6376 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 22 ms 4792 KB Output is correct
3 Correct 22 ms 4688 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 5 ms 1372 KB Output is correct
6 Correct 31 ms 6376 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 39 ms 7316 KB Output is correct
9 Correct 40 ms 7660 KB Output is correct
10 Correct 58 ms 11104 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 22 ms 4792 KB Output is correct
3 Correct 22 ms 4688 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 5 ms 1372 KB Output is correct
6 Correct 31 ms 6376 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 39 ms 7316 KB Output is correct
9 Correct 40 ms 7660 KB Output is correct
10 Correct 58 ms 11104 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 59 ms 10516 KB Output is correct
15 Correct 37 ms 6900 KB Output is correct
16 Correct 55 ms 10080 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 56 ms 10664 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 35 ms 6376 KB Output is correct
3 Correct 35 ms 6404 KB Output is correct
4 Correct 51 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 35 ms 6376 KB Output is correct
3 Correct 35 ms 6404 KB Output is correct
4 Correct 51 ms 8796 KB Output is correct
5 Correct 58 ms 9768 KB Output is correct
6 Correct 55 ms 9460 KB Output is correct
7 Correct 62 ms 9560 KB Output is correct
8 Correct 54 ms 9312 KB Output is correct
9 Correct 37 ms 6392 KB Output is correct
10 Correct 52 ms 9312 KB Output is correct
11 Correct 52 ms 9048 KB Output is correct
12 Correct 37 ms 6476 KB Output is correct
13 Correct 37 ms 6652 KB Output is correct
14 Correct 36 ms 6840 KB Output is correct
15 Correct 39 ms 6896 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 34 ms 7096 KB Output is correct
18 Correct 35 ms 6404 KB Output is correct
19 Correct 35 ms 6392 KB Output is correct
20 Correct 53 ms 9308 KB Output is correct
21 Correct 52 ms 9052 KB Output is correct
22 Correct 56 ms 9056 KB Output is correct