Submission #645802

# Submission time Handle Problem Language Result Execution time Memory
645802 2022-09-28T03:15:31 Z slime Mechanical Doll (IOI18_doll) C++14
49 / 100
120 ms 12100 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++;
  }

  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 1 ms 212 KB Output is correct
2 Correct 19 ms 2388 KB Output is correct
3 Correct 13 ms 1876 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 1876 KB Output is correct
6 Correct 20 ms 2736 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 19 ms 2388 KB Output is correct
3 Correct 13 ms 1876 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 1876 KB Output is correct
6 Correct 20 ms 2736 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 63 ms 6884 KB Output is correct
9 Correct 74 ms 7496 KB Output is correct
10 Incorrect 118 ms 12100 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 19 ms 2388 KB Output is correct
3 Correct 13 ms 1876 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 8 ms 1876 KB Output is correct
6 Correct 20 ms 2736 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 63 ms 6884 KB Output is correct
9 Correct 74 ms 7496 KB Output is correct
10 Incorrect 118 ms 12100 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 300 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 57 ms 5912 KB Output is correct
3 Partially correct 98 ms 9508 KB Output is partially correct
4 Partially correct 112 ms 10788 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 57 ms 5912 KB Output is correct
3 Partially correct 98 ms 9508 KB Output is partially correct
4 Partially correct 112 ms 10788 KB Output is partially correct
5 Partially correct 116 ms 11036 KB Output is partially correct
6 Partially correct 114 ms 10816 KB Output is partially correct
7 Partially correct 114 ms 10840 KB Output is partially correct
8 Partially correct 111 ms 10652 KB Output is partially correct
9 Partially correct 101 ms 9668 KB Output is partially correct
10 Partially correct 120 ms 10696 KB Output is partially correct
11 Partially correct 107 ms 10584 KB Output is partially correct
12 Partially correct 101 ms 9572 KB Output is partially correct
13 Correct 59 ms 6028 KB Output is correct
14 Partially correct 100 ms 9664 KB Output is partially correct
15 Partially correct 101 ms 9780 KB Output is partially correct
16 Partially correct 3 ms 596 KB Output is partially correct
17 Correct 56 ms 5976 KB Output is correct
18 Correct 57 ms 5912 KB Output is correct
19 Partially correct 105 ms 9492 KB Output is partially correct
20 Partially correct 110 ms 10560 KB Output is partially correct
21 Partially correct 106 ms 10652 KB Output is partially correct
22 Partially correct 109 ms 10648 KB Output is partially correct