Submission #1366701

#TimeUsernameProblemLanguageResultExecution timeMemory
1366701mannshah1211Prisoner Challenge (IOI22_prison)C++20
65 / 100
5 ms1092 KiB
#include "prison.h"

#include <vector>
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> devise_strategy(int n) {
  auto setbit = [&](int x, int b) {
    return ((x >> b) & 1);
  };
  vector<vector<int>> s(25, vector<int>(n + 1));
  for (int i = 1; i <= 24; i++) {
    int j = (i + 1) / 2, k = (i + 1) % 2;
    if (j % 2) {
      s[i][0] = 1; // if j is an ODD bit, inspect bag B, so BAG A is on the board
    } else {
      s[i][0] = 0; // if j is an EVEN bit, inspect bag A, so BAG B is on the board
    }
    // we dont need anything == 0 on the board
    // and if we see anything == 0 then we can be sure that thats from the first time
    for (int l = 1; l <= n; l++) {
      if (setbit(l, j)) {
        if (!k) { 
          if (j % 2) { // k represents BAG A, and (l >> j) & 1 represents BAG B
            s[i][l] = -1;
          } else {
            s[i][l] = -2;
          }
        } else {
          if (setbit(l, j - 1)) { // 
            if (j == 1) { // inspected BAG B in this case
              s[i][l] = -1;
            } else {
              s[i][l] = 2 * (j - 1);
            }
          } else {
            if (j == 1) {
              s[i][l] = -2;
            } else {
              s[i][l] = 2 * (j - 1) - 1;
            }
          }
        }
      } else {
        if (!setbit(l, j)) {
          if (k) {
            if (j % 2) {
              s[i][l] = -2;
            } else {
              s[i][l] = -1;
            }
          } else {
            if (setbit(l, j - 1)) {
              if (j == 1) {
                s[i][l] = -1;
              } else {
                s[i][l] = 2 * (j - 1);
              }
            } else {
              if (j == 1) {
                s[i][l] = -2;
              } else {
                s[i][l] = 2 * (j - 1) - 1;
              }
            }
          }
        }
      }
    }
  }
  s[0][0] = 1;
  for (int l = 1; l <= n; l++) {
    s[0][l] = 23 + ((l >> 12) & 1);
  }
  return s;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...