답안 #827782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827782 2023-08-16T18:30:32 Z WLZ 자동 인형 (IOI18_doll) C++17
84 / 100
116 ms 15868 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;
  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 1 ms 212 KB Output is correct
2 Correct 32 ms 5824 KB Output is correct
3 Correct 30 ms 6148 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 48 ms 8132 KB Output is correct
7 Runtime error 1 ms 340 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 32 ms 5824 KB Output is correct
3 Correct 30 ms 6148 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 48 ms 8132 KB Output is correct
7 Runtime error 1 ms 340 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 32 ms 5824 KB Output is correct
3 Correct 30 ms 6148 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 7 ms 1364 KB Output is correct
6 Correct 48 ms 8132 KB Output is correct
7 Runtime error 1 ms 340 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 49 ms 9876 KB Output is correct
3 Correct 53 ms 10628 KB Output is correct
4 Correct 81 ms 15028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 49 ms 9876 KB Output is correct
3 Correct 53 ms 10628 KB Output is correct
4 Correct 81 ms 15028 KB Output is correct
5 Correct 86 ms 15868 KB Output is correct
6 Correct 102 ms 15580 KB Output is correct
7 Correct 116 ms 15736 KB Output is correct
8 Correct 84 ms 15408 KB Output is correct
9 Correct 52 ms 10604 KB Output is correct
10 Correct 81 ms 15268 KB Output is correct
11 Correct 86 ms 15020 KB Output is correct
12 Correct 52 ms 10864 KB Output is correct
13 Correct 53 ms 10288 KB Output is correct
14 Correct 53 ms 11332 KB Output is correct
15 Correct 55 ms 11464 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 50 ms 9916 KB Output is correct
18 Correct 51 ms 9876 KB Output is correct
19 Correct 52 ms 10876 KB Output is correct
20 Correct 82 ms 15176 KB Output is correct
21 Correct 83 ms 15036 KB Output is correct
22 Correct 97 ms 15156 KB Output is correct