Submission #836343

# Submission time Handle Problem Language Result Execution time Memory
836343 2023-08-24T10:23:34 Z Johann Mechanical Doll (IOI18_doll) C++14
53 / 100
87 ms 16888 KB
#include "doll.h"
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

int switches;
vector<int> X, Y;
int newSwitch()
{
  X.push_back(0), Y.push_back(0);
  return --switches;
}
void setSwitch(vector<int> &XY, int switchnum, int dest)
{
  XY[-switchnum - 1] = dest;
}
int getSwitch(vector<int> &XY, int i) { return XY[-i - 1]; }

void create_circuit(int M, std::vector<int> A)
{
  int N = A.size();
  switches = 0;

  vi C(M + 1);

  vvi order(M + 1);
  A.push_back(0);
  for (int i = 0; i < sz(A); ++i)
    order[A[i]].push_back(A[(i + 1) % sz(A)]);

  for (int i = 0; i < sz(order); ++i)
  {
    if (order[i].empty())
      C[i] = 0;
    else if (sz(order[i]) == 1)
      C[i] = order[i][0];
    else
    {
      int firstSwitch = newSwitch();
      C[i] = firstSwitch;
      vi layer = {firstSwitch};
      while (sz(order[i]) > 2 * sz(layer))
      {
        vi nlayer;
        // the order of these loops is important!
        for (int s : layer)
        {
          setSwitch(X, s, newSwitch());
          nlayer.push_back(getSwitch(X, s));
        }
        for (int s : layer)
        {
          setSwitch(Y, s, newSwitch());
          nlayer.push_back(getSwitch(Y, s));
        }
        swap(layer, nlayer);
      }

      int idx = 0;
      for (int j = 0; j < sz(layer); ++j)
        setSwitch(X, layer[j],
                  (idx < sz(order[i]) - 1) ? order[i][idx++] : firstSwitch);
      for (int j = 0; j < sz(layer); ++j)
        setSwitch(Y, layer[j],
                  ((idx < sz(order[i]) - 1) || (j == sz(layer) - 1)) ? order[i][idx++] : firstSwitch);
    }
  }

  answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:29:7: warning: unused variable 'N' [-Wunused-variable]
   29 |   int N = A.size();
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 19 ms 6352 KB Output is correct
3 Correct 21 ms 5324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 3920 KB Output is correct
6 Correct 24 ms 7628 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 6352 KB Output is correct
3 Correct 21 ms 5324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 3920 KB Output is correct
6 Correct 24 ms 7628 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 38 ms 7248 KB Output is correct
9 Correct 35 ms 8528 KB Output is correct
10 Correct 52 ms 11332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 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 6352 KB Output is correct
3 Correct 21 ms 5324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 3920 KB Output is correct
6 Correct 24 ms 7628 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 38 ms 7248 KB Output is correct
9 Correct 35 ms 8528 KB Output is correct
10 Correct 52 ms 11332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 64 ms 11524 KB Output is correct
15 Correct 36 ms 5996 KB Output is correct
16 Correct 56 ms 10248 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 58 ms 12092 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Output is partially correct
2 Correct 31 ms 6468 KB Output is correct
3 Partially correct 59 ms 8152 KB Output is partially correct
4 Partially correct 54 ms 8904 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 212 KB Output is partially correct
2 Correct 31 ms 6468 KB Output is correct
3 Partially correct 59 ms 8152 KB Output is partially correct
4 Partially correct 54 ms 8904 KB Output is partially correct
5 Partially correct 82 ms 13204 KB Output is partially correct
6 Partially correct 82 ms 16168 KB Output is partially correct
7 Partially correct 87 ms 15788 KB Output is partially correct
8 Partially correct 81 ms 16888 KB Output is partially correct
9 Partially correct 49 ms 10556 KB Output is partially correct
10 Partially correct 76 ms 16852 KB Output is partially correct
11 Partially correct 76 ms 14800 KB Output is partially correct
12 Partially correct 50 ms 11100 KB Output is partially correct
13 Partially correct 52 ms 9776 KB Output is partially correct
14 Partially correct 53 ms 9424 KB Output is partially correct
15 Partially correct 51 ms 9060 KB Output is partially correct
16 Partially correct 2 ms 564 KB Output is partially correct
17 Partially correct 41 ms 8396 KB Output is partially correct
18 Partially correct 40 ms 8392 KB Output is partially correct
19 Partially correct 43 ms 9036 KB Output is partially correct
20 Partially correct 60 ms 13072 KB Output is partially correct
21 Partially correct 70 ms 13196 KB Output is partially correct
22 Partially correct 56 ms 12104 KB Output is partially correct