Submission #106723

# Submission time Handle Problem Language Result Execution time Memory
106723 2019-04-19T21:26:06 Z ppnxblstr Mechanical Doll (IOI18_doll) C++14
53 / 100
323 ms 42436 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

int swcnt;
int newswitch(){
    return ++swcnt;
}
class fakeswitch{
public:
    fakeswitch* l;
    fakeswitch* r;
    bool t;
    int val;
    fakeswitch(int x = -1) : l(nullptr), r(nullptr), val(x), t(false) {}
};
fakeswitch* buildfakesw(int lv){
    if(lv == 0) return new fakeswitch(0);
    fakeswitch* cur = new fakeswitch();
    cur->l = buildfakesw(lv-1);
    cur->r = buildfakesw(lv-1);
    return cur;
}
void trav(fakeswitch* cur, int key){
    if(cur->l == nullptr && cur->r == nullptr){
        cur->val = key;
        return;
    }
    if(cur->t) trav(cur->r, key);
    else trav(cur->l, key);
    cur->t = !cur->t;
}
int realize(fakeswitch* cur, vector<int>& X, vector<int>& Y, const vector<int>& v, int root = 0){
    if(cur->val >= 0){
        if(v[cur->val] == -1) return root;
        return v[cur->val];
    }
    int c = -newswitch();
    if(root == 0) root = c;
    X[-1-c] = realize(cur->l, X, Y, v, root);
    Y[-1-c] = realize(cur->r, X, Y, v, root);
    return c;
}
void debug(fakeswitch* sw){
    if(sw == nullptr) return;
    debug(sw->l);
    printf(" %d",sw->val);
    debug(sw->r);
}
int count(fakeswitch* sw){
    if(sw == nullptr || sw->val >= 0) return 0;
    return count(sw->l) + count(sw->r) + 1;
}
vector<int> pot = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144};
void buildsw(vector<int>& C, vector<int>& X, vector<int>& Y, int& trig, vector<int> ord){
    int z = ord.size();
    int idx = lower_bound(pot.begin(), pot.end(), z) - pot.begin();
    fakeswitch* root = buildfakesw(idx);
    int k = ord.back();
    ord.pop_back();
    while(ord.size() < pot[idx]-1) ord.push_back(-1);
    ord.push_back(k);
    for(int i = 0; i < pot[idx]; i++) trav(root, i);
    C[trig] = realize(root, X, Y, ord);
}
vector<int> bckt[200005];
void create_circuit(int M, vector<int> A) {
  int N = A.size();
  bckt[0].push_back(A[0]);
  for(int i = 1; i < N; i++){
      bckt[A[i-1]].push_back(A[i]);
  }
  bckt[A[N-1]].push_back(0);
  vector<int> C;
  C.resize(M+1);
  vector<int> X, Y;
  X.resize(400005, 1e9);
  Y.resize(400005, 1e9);
  for(int i = 0; i <= M; i++){
      if(bckt[i].empty()) continue;
      auto buf = bckt[i];
      buildsw(C,X,Y,i,buf);
  }
  while(!X.empty() && X.back() == 1e9) X.pop_back();
  while(!Y.empty() && Y.back() == 1e9) Y.pop_back();
  answer(C, X, Y);
}

Compilation message

doll.cpp: In constructor 'fakeswitch::fakeswitch(int)':
doll.cpp:14:9: warning: 'fakeswitch::val' will be initialized after [-Wreorder]
   14 |     int val;
      |         ^~~
doll.cpp:13:10: warning:   'bool fakeswitch::t' [-Wreorder]
   13 |     bool t;
      |          ^
doll.cpp:15:5: warning:   when initialized here [-Wreorder]
   15 |     fakeswitch(int x = -1) : l(nullptr), r(nullptr), val(x), t(false) {}
      |     ^~~~~~~~~~
doll.cpp: In function 'void buildsw(std::vector<int>&, std::vector<int>&, std::vector<int>&, int&, std::vector<int>)':
doll.cpp:61:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   61 |     while(ord.size() < pot[idx]-1) ord.push_back(-1);
      |           ~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8012 KB Output is correct
2 Correct 52 ms 13816 KB Output is correct
3 Correct 63 ms 13432 KB Output is correct
4 Correct 7 ms 8012 KB Output is correct
5 Correct 18 ms 9292 KB Output is correct
6 Correct 106 ms 16264 KB Output is correct
7 Correct 10 ms 8012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8012 KB Output is correct
2 Correct 52 ms 13816 KB Output is correct
3 Correct 63 ms 13432 KB Output is correct
4 Correct 7 ms 8012 KB Output is correct
5 Correct 18 ms 9292 KB Output is correct
6 Correct 106 ms 16264 KB Output is correct
7 Correct 10 ms 8012 KB Output is correct
8 Correct 76 ms 19168 KB Output is correct
9 Correct 139 ms 19100 KB Output is correct
10 Correct 129 ms 24924 KB Output is correct
11 Correct 6 ms 8012 KB Output is correct
12 Correct 8 ms 8012 KB Output is correct
13 Correct 6 ms 8080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8012 KB Output is correct
2 Correct 52 ms 13816 KB Output is correct
3 Correct 63 ms 13432 KB Output is correct
4 Correct 7 ms 8012 KB Output is correct
5 Correct 18 ms 9292 KB Output is correct
6 Correct 106 ms 16264 KB Output is correct
7 Correct 10 ms 8012 KB Output is correct
8 Correct 76 ms 19168 KB Output is correct
9 Correct 139 ms 19100 KB Output is correct
10 Correct 129 ms 24924 KB Output is correct
11 Correct 6 ms 8012 KB Output is correct
12 Correct 8 ms 8012 KB Output is correct
13 Correct 6 ms 8080 KB Output is correct
14 Correct 137 ms 30288 KB Output is correct
15 Correct 79 ms 19268 KB Output is correct
16 Correct 122 ms 25088 KB Output is correct
17 Correct 8 ms 8012 KB Output is correct
18 Correct 8 ms 8012 KB Output is correct
19 Correct 8 ms 8012 KB Output is correct
20 Correct 128 ms 27368 KB Output is correct
21 Correct 6 ms 8012 KB Output is correct
22 Correct 9 ms 8012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 8088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 7 ms 8012 KB Output is partially correct
2 Correct 142 ms 19924 KB Output is correct
3 Partially correct 299 ms 30188 KB Output is partially correct
4 Partially correct 305 ms 30948 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 7 ms 8012 KB Output is partially correct
2 Correct 142 ms 19924 KB Output is correct
3 Partially correct 299 ms 30188 KB Output is partially correct
4 Partially correct 305 ms 30948 KB Output is partially correct
5 Partially correct 156 ms 35396 KB Output is partially correct
6 Partially correct 166 ms 38596 KB Output is partially correct
7 Partially correct 184 ms 37548 KB Output is partially correct
8 Partially correct 219 ms 40464 KB Output is partially correct
9 Partially correct 204 ms 31216 KB Output is partially correct
10 Partially correct 323 ms 40756 KB Output is partially correct
11 Partially correct 223 ms 42436 KB Output is partially correct
12 Partially correct 121 ms 30512 KB Output is partially correct
13 Partially correct 109 ms 28056 KB Output is partially correct
14 Partially correct 117 ms 27268 KB Output is partially correct
15 Partially correct 106 ms 25940 KB Output is partially correct
16 Partially correct 9 ms 8524 KB Output is partially correct
17 Partially correct 98 ms 25640 KB Output is partially correct
18 Partially correct 136 ms 25732 KB Output is partially correct
19 Partially correct 117 ms 26996 KB Output is partially correct
20 Partially correct 136 ms 32016 KB Output is partially correct
21 Partially correct 167 ms 37700 KB Output is partially correct
22 Partially correct 122 ms 30744 KB Output is partially correct