답안 #827786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827786 2023-08-16T18:37:48 Z WLZ 자동 인형 (IOI18_doll) C++17
100 / 100
121 ms 16484 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

struct node {
  int idx, state;
  node *left, *right;
};

int n, m, cur_idx = 0, max_depth = 0, next_power = 1;
vector<int> a, c, x, y;
set<int> removed_bits;

node *build(int l, int r, int pw, int depth = 0) {
  max_depth = max(max_depth, depth);
  if (pw == 1) return nullptr;
  if (((next_power - n) & pw) && !removed_bits.count(pw)) {
    removed_bits.insert(pw);
    return nullptr;
  }
  x.push_back(-1); y.push_back(-1);
  node *ans = new node{cur_idx++, 0, nullptr, nullptr};
  ans->left = build(l, r - pw / 2, pw / 2, depth + 1);
  ans->right = build(r - pw / 2 + 1, r, pw / 2, depth + 1);
  if (ans->left != nullptr) x[ans->idx] = -(ans->left->idx + 1);
  if (ans->right != nullptr) y[ans->idx] = -(ans->right->idx + 1);
  return ans;
}

void create_circuit(int M, std::vector<int> A) {
  n = (int) A.size(), m = M, a = A;
  if (n == 1) {
    vector<int> c(m + 1, 0), x(0), y(0);
    c[0] = a[0]; c[a[0]] = 0;
    answer(c, x, y);
    return;
  }
  c.resize(m + 1); c[0] = a[0];
  for (int i = 1; i <= m; i++) c[i] = -1;
  a.erase(a.begin()); a.push_back(0);
  while (next_power < n) next_power *= 2;
  node *root = build(0, n - 1, next_power); node *cur = root;
  int ptr = 0;
  bool first = n % 2;
  while (ptr < n) {
    int depth = 1;
    while ((cur->state == 0 && cur->left != nullptr) || (cur->state == 1 && cur->right != nullptr)) {
      depth++;
      cur->state = !cur->state;
      if (cur->state == 1) cur = cur->left;
      else cur = cur->right;
    }
    if (depth == max_depth && ptr < n) {
      if (!first) {
        if (cur->state == 0) x[cur->idx] = a[ptr++];
        else y[cur->idx] = a[ptr++];
      }
      first = false;
    }
    cur->state = !cur->state;
    cur = root;
  }
  answer(c, x, y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 32 ms 5812 KB Output is correct
3 Correct 30 ms 6168 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1372 KB Output is correct
6 Correct 45 ms 8120 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 32 ms 5812 KB Output is correct
3 Correct 30 ms 6168 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1372 KB Output is correct
6 Correct 45 ms 8120 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 57 ms 10136 KB Output is correct
9 Correct 62 ms 11612 KB Output is correct
10 Correct 94 ms 15432 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 32 ms 5812 KB Output is correct
3 Correct 30 ms 6168 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1372 KB Output is correct
6 Correct 45 ms 8120 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 57 ms 10136 KB Output is correct
9 Correct 62 ms 11612 KB Output is correct
10 Correct 94 ms 15432 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 89 ms 14812 KB Output is correct
15 Correct 60 ms 11540 KB Output is correct
16 Correct 121 ms 16048 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 86 ms 16484 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 53 ms 8996 KB Output is correct
3 Correct 51 ms 9624 KB Output is correct
4 Correct 81 ms 13620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 53 ms 8996 KB Output is correct
3 Correct 51 ms 9624 KB Output is correct
4 Correct 81 ms 13620 KB Output is correct
5 Correct 86 ms 14436 KB Output is correct
6 Correct 84 ms 14088 KB Output is correct
7 Correct 93 ms 14200 KB Output is correct
8 Correct 95 ms 13936 KB Output is correct
9 Correct 68 ms 9672 KB Output is correct
10 Correct 82 ms 13860 KB Output is correct
11 Correct 85 ms 13520 KB Output is correct
12 Correct 52 ms 9924 KB Output is correct
13 Correct 65 ms 9300 KB Output is correct
14 Correct 56 ms 10372 KB Output is correct
15 Correct 68 ms 10552 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 50 ms 9040 KB Output is correct
18 Correct 52 ms 9020 KB Output is correct
19 Correct 53 ms 9940 KB Output is correct
20 Correct 93 ms 13728 KB Output is correct
21 Correct 80 ms 13572 KB Output is correct
22 Correct 83 ms 13604 KB Output is correct