Submission #971969

# Submission time Handle Problem Language Result Execution time Memory
971969 2024-04-29T15:32:51 Z onlk97 Mechanical Doll (IOI18_doll) C++14
85.553 / 100
86 ms 15116 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
vector <int> v[100010],C,X,Y;
vector <int> seq;
void gen(int len){
    seq={1};
    int add=1;
    while (seq.size()<len){
        vector <int> c;
        for (int i=0; i<seq.size(); i++){
            c.push_back(seq[i]);
            c.push_back(seq[i]+add);
        }
        seq=c;
        add*=2;
    }
}
int rt,ptr;
vector <int> use;
int build(int rem,int po){
    if (po==1){
        use.push_back(seq[ptr]);
        ptr++;
        return -1e9;
    }
    int cur=-(1+X.size());
    X.push_back(-1e9); Y.push_back(-1e9);
    int br=X.size()-1;
    if (rem<=po/2){
        int tf=build(rem,po/2);
        X[br]=tf;
        Y[br]=rt;
        ptr+=po/2;
    } else {
        int tf=build(rem-po/2,po/2);
        X[br]=tf;
        int tg=build(po/2,po/2);
        Y[br]=tg;
    }
    return cur;
}
void create_circuit(int M,vector <int> A){
    v[0].push_back(A[0]);
    for (int i=1; i<A.size(); i++) v[A[i-1]].push_back(A[i]);
    v[A.back()].push_back(0);
    for (int i=0; i<=M; i++) C.push_back(0);
    for (int i=0; i<=M; i++){
        if (v[i].empty()) continue;
        if (v[i].size()==1){
            C[i]=v[i][0];
            continue;
        }
        int sz=v[i].size(),rd=1;
        while (rd<sz) rd*=2;
        gen(rd);
        rt=-(1+X.size());
        C[i]=rt;
        int ori=X.size();
        use.clear(); ptr=0;
        build(sz,rd);
        vector <pair <int,int> > vv;
        for (int j=ori; j<X.size(); j++){
            if (X[j]==-1e9) vv.push_back({j,0});
            if (Y[j]==-1e9) vv.push_back({j,1});
        }
        vector <int> suse;
        for (int j:use) suse.push_back(j);
        sort(suse.begin(),suse.end());
        for (int j=0; j<use.size(); j++) use[j]=lower_bound(suse.begin(),suse.end(),use[j])-suse.begin();
        //assert(vv.size()==use.size());
        for (int j=0; j<vv.size(); j++){
            if (!vv[j].second) X[vv[j].first]=v[i][use[j]];
            else Y[vv[j].first]=v[i][use[j]];
        }
    }
    answer(C,X,Y);
}

Compilation message

doll.cpp: In function 'void gen(int)':
doll.cpp:9:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    9 |     while (seq.size()<len){
      |            ~~~~~~~~~~^~~~
doll.cpp:11:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |         for (int i=0; i<seq.size(); i++){
      |                       ~^~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i=1; i<A.size(); i++) v[A[i-1]].push_back(A[i]);
      |                   ~^~~~~~~~~
doll.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (int j=ori; j<X.size(); j++){
      |                         ~^~~~~~~~~
doll.cpp:70:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for (int j=0; j<use.size(); j++) use[j]=lower_bound(suse.begin(),suse.end(),use[j])-suse.begin();
      |                       ~^~~~~~~~~~~
doll.cpp:72:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int j=0; j<vv.size(); j++){
      |                       ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 19 ms 6876 KB Output is correct
3 Correct 15 ms 6616 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 11 ms 4188 KB Output is correct
6 Correct 27 ms 8544 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 19 ms 6876 KB Output is correct
3 Correct 15 ms 6616 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 11 ms 4188 KB Output is correct
6 Correct 27 ms 8544 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 42 ms 9884 KB Output is correct
9 Correct 40 ms 9792 KB Output is correct
10 Correct 81 ms 12984 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 19 ms 6876 KB Output is correct
3 Correct 15 ms 6616 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 11 ms 4188 KB Output is correct
6 Correct 27 ms 8544 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 42 ms 9884 KB Output is correct
9 Correct 40 ms 9792 KB Output is correct
10 Correct 81 ms 12984 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 81 ms 14792 KB Output is correct
15 Correct 43 ms 8508 KB Output is correct
16 Correct 66 ms 11672 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 74 ms 13676 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2656 KB Output is correct
7 Correct 1 ms 2656 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2656 KB Output is correct
2 Correct 52 ms 10432 KB Output is correct
3 Correct 55 ms 11976 KB Output is correct
4 Correct 79 ms 15116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2656 KB Output is correct
2 Correct 52 ms 10432 KB Output is correct
3 Correct 55 ms 11976 KB Output is correct
4 Correct 79 ms 15116 KB Output is correct
5 Partially correct 86 ms 15064 KB Output is partially correct
6 Partially correct 80 ms 14644 KB Output is partially correct
7 Partially correct 81 ms 14588 KB Output is partially correct
8 Partially correct 78 ms 14116 KB Output is partially correct
9 Partially correct 51 ms 10528 KB Output is partially correct
10 Partially correct 79 ms 15012 KB Output is partially correct
11 Partially correct 61 ms 12624 KB Output is partially correct
12 Partially correct 41 ms 9084 KB Output is partially correct
13 Partially correct 60 ms 10544 KB Output is partially correct
14 Partially correct 54 ms 10456 KB Output is partially correct
15 Partially correct 55 ms 10732 KB Output is partially correct
16 Partially correct 2 ms 2908 KB Output is partially correct
17 Partially correct 41 ms 8872 KB Output is partially correct
18 Partially correct 45 ms 9528 KB Output is partially correct
19 Partially correct 43 ms 8856 KB Output is partially correct
20 Partially correct 60 ms 12116 KB Output is partially correct
21 Partially correct 67 ms 12220 KB Output is partially correct
22 Partially correct 62 ms 11708 KB Output is partially correct