Submission #645801

# Submission time Handle Problem Language Result Execution time Memory
645801 2022-09-28T03:11:37 Z slime Mechanical Doll (IOI18_doll) C++14
2 / 100
279 ms 262144 KB
 #include "doll.h"
#include "bits/stdc++.h"
using namespace std;

void create_circuit(int M, std::vector<int> A);

void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);

int lg(int x) {
  return 32 - __builtin_clz(x) - 1;
}
void create_circuit(int M, std::vector<int> A) {
  int N = A.size();
  int freq[M + 1];
  for(int i=0; i<=M; i++) freq[i] = 0;
  for(int i=0; i<N; i++) freq[A[i]]++;
  freq[0]++;
  vector<int> C(M + 1);
  for(int i=0; i<=M; i++) C[i] = 0;
  C[0] = A[0];
  vector<int> sequence;
  for(int i=0; i<N; i++) {
    if(freq[A[i]] == 1) {
      C[A[i]] = (i+1 == N ? 0 : A[i+1]);
    }
    else {
      sequence.push_back((i+1 == N ? 0 : A[i+1]));
      C[A[i]] = -1;
    }
  }

  if(sequence.empty()) {
    answer(C, sequence, sequence);
    return;
  }
  
  int len = sequence.size();

  while((1 << lg(len)) != len) {
    sequence.push_back(-1);
    swap(sequence[sequence.size() - 2], sequence[sequence.size() - 1]);
  }

  len = sequence.size();
  int layers = lg(len);

  vector<int> X, Y;
  X.resize((1 << layers) - 1);
  Y.resize((1 << layers) - 1);

  for(int i=0; i<(1 << layers) - 1; i++) {
    if(2*i+1 < (1<<layers) - 1) X[i] = -(2*i+1 + 1);
    if(2*i+2 < (1<<layers) - 1) Y[i] = -(2*i+2 + 1);
  }
  for(int i=0; i<len; i++) {
    int cp = 0;
    string str;
    for(int j=0; j<lg(len)-1; j++) {
      if(i & (1<<j)) {
        cp = cp * 2 + 2;
        str += "Y";
      }
      else {
        cp = cp * 2 + 1;
        str += "X";
      }
    }
    if(i & (1 << (lg(len) - 1))) {
      str += "Y";
      Y[cp] = sequence[i];
    }
    else {
      str += "X";
      X[cp] = sequence[i];
    }
    //cout << cp << " " << str << "\n";
  }


  answer(C, X, Y);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 17 ms 2736 KB Output is correct
3 Correct 13 ms 2260 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1836 KB Output is correct
6 Correct 19 ms 3232 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 17 ms 2736 KB Output is correct
3 Correct 13 ms 2260 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1836 KB Output is correct
6 Correct 19 ms 3232 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Runtime error 279 ms 262144 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 17 ms 2736 KB Output is correct
3 Correct 13 ms 2260 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1836 KB Output is correct
6 Correct 19 ms 3232 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Runtime error 279 ms 262144 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 254 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 243 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 243 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -