Submission #628605

# Submission time Handle Problem Language Result Execution time Memory
628605 2022-08-13T14:27:25 Z evenvalue Mechanical Doll (IOI18_doll) C++17
100 / 100
88 ms 11404 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;

using int64 = long long;
using ld = long double;

constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;

vector<int> C;
vector<int> X, Y;

int add_switch(const int x = kInf, const int y = kInf) {
  X.push_back(x);
  Y.push_back(y);
  return -((int)X.size());
}


int calc_elements(const int n) {
  const int h = 32 - __builtin_clz(n) - (__builtin_popcount(n) == 1);
  return (1 << h);
}

void create_circuit(int m, std::vector<int> A) {
  C.resize(m + 1, -1);

  A.push_back(0);
  const int n = A.size();
  const int elems = calc_elements(n);
  const int unused = elems - n;

  vector<pair<int, int>> trigger_places(elems, {-1, -1});

  function<void(int, int, int, int, int)> dfs = [&](const int x, const int l, const int r, const int depth, int path) {
    const int mid = (l + r) / 2;
    //left child
    if (mid < unused) {
      X[x] = -1;
    } else if (l == mid) {
      X[x] = path;
      trigger_places[path] = {x, 0};
    } else {
      X[x] = add_switch();
      dfs(-X[x] - 1, l, mid, depth + 1, path);
    }
    path += (1 << depth);
    if (mid + 1 == r) {
      Y[x] = path;
      trigger_places[path] = {x, 1};
    } else {
      Y[x] = add_switch();
      dfs(-Y[x] - 1, mid + 1, r, depth + 1, path);
    }
  };

  add_switch();
  dfs(0, 0, elems - 1, 0, 0);

  for (int i = 0, j = 0; i < elems; i++) {
    if (trigger_places[i] == make_pair(-1, -1)) continue;
    const auto [s, dir] = trigger_places[i];
    (dir == 0 ? X[s] : Y[s]) = A[j];
    j++;
  }

  answer(C, X, Y);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 31 ms 5200 KB Output is correct
3 Correct 29 ms 4788 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 9 ms 1492 KB Output is correct
6 Correct 52 ms 6512 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 31 ms 5200 KB Output is correct
3 Correct 29 ms 4788 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 9 ms 1492 KB Output is correct
6 Correct 52 ms 6512 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 48 ms 8172 KB Output is correct
9 Correct 55 ms 8520 KB Output is correct
10 Correct 88 ms 11404 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 31 ms 5200 KB Output is correct
3 Correct 29 ms 4788 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
5 Correct 9 ms 1492 KB Output is correct
6 Correct 52 ms 6512 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 48 ms 8172 KB Output is correct
9 Correct 55 ms 8520 KB Output is correct
10 Correct 88 ms 11404 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 70 ms 10872 KB Output is correct
15 Correct 70 ms 7752 KB Output is correct
16 Correct 69 ms 10672 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 86 ms 11024 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 39 ms 7316 KB Output is correct
3 Correct 37 ms 7384 KB Output is correct
4 Correct 58 ms 10044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 39 ms 7316 KB Output is correct
3 Correct 37 ms 7384 KB Output is correct
4 Correct 58 ms 10044 KB Output is correct
5 Correct 62 ms 10516 KB Output is correct
6 Correct 66 ms 10276 KB Output is correct
7 Correct 59 ms 10432 KB Output is correct
8 Correct 61 ms 10148 KB Output is correct
9 Correct 36 ms 7284 KB Output is correct
10 Correct 58 ms 10172 KB Output is correct
11 Correct 60 ms 10020 KB Output is correct
12 Correct 42 ms 7540 KB Output is correct
13 Correct 54 ms 7504 KB Output is correct
14 Correct 41 ms 7632 KB Output is correct
15 Correct 60 ms 7624 KB Output is correct
16 Correct 2 ms 572 KB Output is correct
17 Correct 38 ms 6696 KB Output is correct
18 Correct 39 ms 7360 KB Output is correct
19 Correct 37 ms 7408 KB Output is correct
20 Correct 62 ms 10044 KB Output is correct
21 Correct 55 ms 10012 KB Output is correct
22 Correct 56 ms 10052 KB Output is correct