Submission #1037768

# Submission time Handle Problem Language Result Execution time Memory
1037768 2024-07-29T08:10:51 Z Mr_Husanboy Mechanical Doll (IOI18_doll) C++17
53 / 100
87 ms 15476 KB
#include "doll.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()

template<typename T>
int len(T &a){
  return a.size();
}

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());


void create_circuit(int m, vector<int> a) {
  int n = a.size();
  vector<int> c(m + 1);
  a.push_back(0);
  c[0] = a[0];
  vector<vector<int>> pos(m + 1);
  for(int i = 0; i < n; i ++){
    pos[a[i]].push_back(i);
  }

  vector<int> x, y;

  auto addx = [&](int from, int to)->void{
    while(len(x) < -from) x.push_back(0);
    x[-from - 1] = to;
  };
  auto addy = [&](int from, int to)->void{
    while(len(y) < -from) y.push_back(0);
    y[-from - 1] = to;
  };

  for(int i = 1; i <= m; i ++){
    if(len(pos[i]) == 0) continue;
    if(len(pos[i]) == 1){
      c[i] = a[pos[i][0] + 1];
      continue;
    }else
    if(len(pos[i]) == 2){
      x.push_back(a[pos[i][0] + 1]); y.push_back(a[pos[i][1] + 1]);
      c[i] = -len(x);
      continue;
    }else
    if(len(pos[i]) == 3){
      int cur = len(x);
      c[i] = -cur - 1;
      x.push_back(-cur - 2);
      x.push_back(a[pos[i][0] + 1]);
      x.push_back(a[pos[i][1] + 1]);
      y.push_back(-cur - 3);
      y.push_back(-cur - 1);
      y.push_back(a[pos[i][2] + 1]);
    }else
    if(len(pos[i]) == 4){
      int cur = len(x);
      c[i] = -cur - 1;
      x.push_back(-cur - 2);
      x.push_back(a[pos[i][0] + 1]);
      x.push_back(a[pos[i][1] + 1]);
      y.push_back(-cur - 3);
      y.push_back(a[pos[i][2] + 1]);
      y.push_back(a[pos[i][3] + 1]);
    }else{
    int b = 32 - __builtin_clz(len(pos[i]) - 1);
    int cur = -len(x);
    c[i] = cur - 1;
    for(int j = 0; j < len(pos[i]) - 1; j ++){
      int x = 1;
      for(int bit = 0; bit < b; bit ++){
        if(j >> bit & 1){
          if(bit < b - 1){
            addy(cur - x, cur - (x * 2 + 1));
          }else{
            addy(cur - x, a[pos[i][j] + 1]);
          }
          x = x * 2 + 1;
        }else{
          if(bit < b - 1)
            addx(cur - x, cur - x * 2);
          else
            addx(cur - x, a[pos[i][j] + 1]);
          x *= 2;
        }
      }
    }
    for(int j = len(pos[i]) - 1; j < (1 << b) - 1; j ++){
      int x = 1;
      for(int bit = 0; bit < b; bit ++){
        if(j >> bit & 1){
          if(bit < b - 1){
            addy(cur - x, cur - (x * 2 + 1));
          }else{
            addy(cur - x, cur - 1);
          }
          x = x * 2 + 1;
        }else{
          if(bit < b - 1){
            addx(cur - x, cur - x * 2);
          }else
            addx(cur - x, cur - 1);
          x = x * 2;
        }
      }
    }
    int x = 1;
    for(int bit = 0; bit < b; bit ++){
      if(bit < b - 1){
        addy(cur - x, cur - (x * 2 + 1));
      }else addy(cur - x, a[pos[i].back() + 1]);
      x = x * 2 + 1;
    }
    }
  }
  answer(c, x, y);

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 16 ms 6488 KB Output is correct
3 Correct 13 ms 5208 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 5 ms 3932 KB Output is correct
6 Correct 23 ms 7892 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 16 ms 6488 KB Output is correct
3 Correct 13 ms 5208 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 5 ms 3932 KB Output is correct
6 Correct 23 ms 7892 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 28 ms 7476 KB Output is correct
9 Correct 29 ms 8536 KB Output is correct
10 Correct 42 ms 11328 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 16 ms 6488 KB Output is correct
3 Correct 13 ms 5208 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 5 ms 3932 KB Output is correct
6 Correct 23 ms 7892 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 28 ms 7476 KB Output is correct
9 Correct 29 ms 8536 KB Output is correct
10 Correct 42 ms 11328 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 50 ms 11024 KB Output is correct
15 Correct 27 ms 6088 KB Output is correct
16 Correct 47 ms 8776 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 47 ms 10624 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 34 ms 7040 KB Output is correct
3 Partially correct 59 ms 9140 KB Output is partially correct
4 Partially correct 62 ms 10308 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 34 ms 7040 KB Output is correct
3 Partially correct 59 ms 9140 KB Output is partially correct
4 Partially correct 62 ms 10308 KB Output is partially correct
5 Partially correct 59 ms 13628 KB Output is partially correct
6 Partially correct 64 ms 14284 KB Output is partially correct
7 Partially correct 63 ms 13984 KB Output is partially correct
8 Partially correct 63 ms 14428 KB Output is partially correct
9 Partially correct 58 ms 9688 KB Output is partially correct
10 Partially correct 87 ms 15476 KB Output is partially correct
11 Partially correct 70 ms 14656 KB Output is partially correct
12 Partially correct 49 ms 9852 KB Output is partially correct
13 Partially correct 41 ms 9348 KB Output is partially correct
14 Partially correct 42 ms 9080 KB Output is partially correct
15 Partially correct 41 ms 9092 KB Output is partially correct
16 Partially correct 1 ms 604 KB Output is partially correct
17 Partially correct 39 ms 8064 KB Output is partially correct
18 Partially correct 49 ms 8056 KB Output is partially correct
19 Partially correct 52 ms 8568 KB Output is partially correct
20 Partially correct 50 ms 11320 KB Output is partially correct
21 Partially correct 61 ms 13628 KB Output is partially correct
22 Partially correct 51 ms 10724 KB Output is partially correct