답안 #815353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815353 2023-08-08T14:21:46 Z rnl42 자동 인형 (IOI18_doll) C++14
53 / 100
96 ms 16856 KB
//#include <bits/stdc++.h>
#include "doll.h"
using namespace std;

int M, N;
vector<int> A;
vector<vector<int>> nexts;
vector<int> C, X, Y;
vector<bool> state;

void push(int* pos, int val) {
  while (*pos < 0) {
    state[-*pos-1].flip();
    pos = !state[-*pos-1] ? &X[-*pos-1] : &Y[-*pos-1];
  }
  int prev = *pos;
  *pos = -1-(int)X.size();
  state.push_back(true);
  X.push_back(prev);
  Y.push_back(val);
}

void create_circuit(int __M, vector<int> __A) {
  M = __M;
  A = __A;
  N = A.size();
  nexts.resize(M+1);
  for (int i = 0; i < N-1; i++) {
    nexts[A[i]].push_back(A[i+1]);
  }
  nexts[A[N-1]].push_back(0);
  C.resize(M+1);
  X.reserve(3*N);
  Y.reserve(3*N);
  C[0] = A[0];
  for (int node = 1; node <= M; node++) {
    if (!nexts[node].empty()) {
      C[node] = nexts[node].front();
      int* root = &C[node];
      for (int i = 1; i < (int)nexts[node].size(); i++) {
        push(root, nexts[node][i]);
      }
    }
  }
  vector<int*> todo;
  for (int i = 0; i <= M; i++) {
    if (C[i] < 0) {
      const int missing = (1<<__lg(2*(int)nexts[i].size()-1))-(int)nexts[i].size();
      if (missing > 0) {
        for (int _ = 0; _ < missing; _++) {
          todo.push_back(&C[i]);
        }
      }
    }
  }
  if (!todo.empty()) {
    for (int i = 0; i < (int)todo.size()-1; i++) {
      push(todo[i], *todo[i+1]);
    }
    const int lastswitch = -1-(int)X.size();
    for (auto& k : C) if (k == 0) { k = lastswitch; break; }
    for (auto& k : X) if (k == 0) { k = lastswitch; break; }
    for (auto& k : Y) if (k == 0) { k = lastswitch; break; }
    X.push_back(*todo[0]);
    Y.push_back(0);
    push(todo.back(), lastswitch);
  }
  answer(C, X, Y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 23 ms 6996 KB Output is correct
3 Correct 22 ms 5908 KB Output is correct
4 Correct 0 ms 232 KB Output is correct
5 Correct 8 ms 3796 KB Output is correct
6 Correct 22 ms 8788 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 23 ms 6996 KB Output is correct
3 Correct 22 ms 5908 KB Output is correct
4 Correct 0 ms 232 KB Output is correct
5 Correct 8 ms 3796 KB Output is correct
6 Correct 22 ms 8788 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 47 ms 8620 KB Output is correct
9 Correct 33 ms 10016 KB Output is correct
10 Correct 52 ms 13208 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 23 ms 6996 KB Output is correct
3 Correct 22 ms 5908 KB Output is correct
4 Correct 0 ms 232 KB Output is correct
5 Correct 8 ms 3796 KB Output is correct
6 Correct 22 ms 8788 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 47 ms 8620 KB Output is correct
9 Correct 33 ms 10016 KB Output is correct
10 Correct 52 ms 13208 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 75 ms 14092 KB Output is correct
15 Correct 43 ms 7224 KB Output is correct
16 Correct 51 ms 11120 KB Output is correct
17 Correct 0 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 58 ms 13276 KB Output is correct
21 Correct 1 ms 284 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 38 ms 6416 KB Output is correct
3 Partially correct 68 ms 10600 KB Output is partially correct
4 Partially correct 90 ms 12024 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 38 ms 6416 KB Output is correct
3 Partially correct 68 ms 10600 KB Output is partially correct
4 Partially correct 90 ms 12024 KB Output is partially correct
5 Partially correct 75 ms 15540 KB Output is partially correct
6 Partially correct 79 ms 16296 KB Output is partially correct
7 Partially correct 79 ms 16004 KB Output is partially correct
8 Partially correct 87 ms 16544 KB Output is partially correct
9 Partially correct 63 ms 10596 KB Output is partially correct
10 Partially correct 94 ms 16200 KB Output is partially correct
11 Partially correct 96 ms 16856 KB Output is partially correct
12 Partially correct 58 ms 11144 KB Output is partially correct
13 Partially correct 54 ms 10624 KB Output is partially correct
14 Partially correct 59 ms 10452 KB Output is partially correct
15 Partially correct 51 ms 10192 KB Output is partially correct
16 Partially correct 2 ms 596 KB Output is partially correct
17 Partially correct 46 ms 9164 KB Output is partially correct
18 Partially correct 46 ms 9160 KB Output is partially correct
19 Partially correct 51 ms 9684 KB Output is partially correct
20 Partially correct 63 ms 12644 KB Output is partially correct
21 Partially correct 78 ms 14916 KB Output is partially correct
22 Partially correct 71 ms 11804 KB Output is partially correct