Submission #812133

# Submission time Handle Problem Language Result Execution time Memory
812133 2023-08-07T07:26:04 Z thimote75 Mechanical Doll (IOI18_doll) C++14
70.6719 / 100
85 ms 12528 KB
#include "doll.h"

#include <bits/stdc++.h>

using namespace std;

using idata = vector<int>;
using bdata = vector<bool>;

using di = pair<int, int>;
using vd = vector<di>;

struct SegTree {
  idata treeIds;
  int rsize = 0;

  int start, height, size;

  void generate (int node, int limit) {
    if (node == 0) return ;

    generate(node >> 1, (limit + 1) >> 1);
    if (node == start) return ;
    for (int u = node; u < node + limit; u ++)
      treeIds[u] = - ((rsize ++) + 1);
  }
  int getId (int node) {
    int count = 0;
    int diam  = height - 1;
    while (node != 1) {
      if (node & 1) count += 1 << diam;

      diam --;
      node >>= 1;
    }

    return count;
  }

  idata X, Y;
  SegTree (idata A) {
    size   = A.size();
    height = ceil(log2(size + 1));
    start  = 1 << height;

    treeIds.resize(start << 1, - 1e9);

    generate(start, size);

    vd g_pos;
    for (int i = 0; i < size; i ++)
      g_pos.push_back({ getId( i + start ), i + start });
    
    sort(g_pos.begin(), g_pos.end());

    for (int i = 0; i < size; i ++)
      treeIds[g_pos [i].second] = A[i];
    
    X.resize(rsize); Y.resize(rsize);
    
    for (int i = 1; i < start; i ++) {
      if (treeIds[i] >= 0 || treeIds[i] == - 1e9) continue ;
      int xid = - (1 + treeIds[i]);

      int n0 = 2 * i;     int vn0 = treeIds[n0] == - 1e9 ? -1 : treeIds[n0];
      int n1 = 2 * i + 1; int vn1 = treeIds[n1] == - 1e9 ? -1 : treeIds[n1];
      X[xid] = vn0;
      Y[xid] = vn1;
    }
  }
};

void create_circuit(int M, vector<int> A) {
  idata C( M + 1, - 1 ); // - 1 is the decision tree root
  
  SegTree tree(A);
  
  idata X = tree.X;
  idata Y = tree.Y;

  int h = 1;
  int p = 0;
  while (h < tree.start) {
    if (tree.treeIds[h * 2 + 1] == - 1e9) {
      Y[p] = h * 2 + 1 >= tree.start ? 0 : - ((tree.rsize ++) + 1);

      if (Y[p] != 0) {
        X.push_back(-1);
        Y.push_back(-1);
      }
    }

    h = (h * 2) + 1;
    p = - (Y[p] + 1);
  }

  answer(C, X, Y);
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Output is partially correct
2 Correct 57 ms 8940 KB Output is correct
3 Partially correct 51 ms 8844 KB Output is partially correct
4 Partially correct 72 ms 12424 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Output is partially correct
2 Correct 57 ms 8940 KB Output is correct
3 Partially correct 51 ms 8844 KB Output is partially correct
4 Partially correct 72 ms 12424 KB Output is partially correct
5 Partially correct 85 ms 12492 KB Output is partially correct
6 Partially correct 81 ms 12424 KB Output is partially correct
7 Partially correct 77 ms 12528 KB Output is partially correct
8 Partially correct 76 ms 12432 KB Output is partially correct
9 Partially correct 46 ms 8936 KB Output is partially correct
10 Partially correct 75 ms 12396 KB Output is partially correct
11 Partially correct 74 ms 12432 KB Output is partially correct
12 Partially correct 47 ms 8880 KB Output is partially correct
13 Correct 48 ms 8916 KB Output is correct
14 Partially correct 55 ms 9012 KB Output is partially correct
15 Partially correct 51 ms 8972 KB Output is partially correct
16 Partially correct 2 ms 564 KB Output is partially correct
17 Correct 46 ms 7332 KB Output is correct
18 Correct 46 ms 8852 KB Output is correct
19 Partially correct 62 ms 8844 KB Output is partially correct
20 Partially correct 74 ms 12432 KB Output is partially correct
21 Partially correct 74 ms 12404 KB Output is partially correct
22 Partially correct 74 ms 12428 KB Output is partially correct