Submission #626702

#TimeUsernameProblemLanguageResultExecution timeMemory
626702flashmtPrisoner Challenge (IOI22_prison)C++17
80 / 100
14 ms1436 KiB
#include <bits/stdc++.h>
using namespace std;
const int BASE = 3;
const int POWER = 8; // 3 ** 8 = 6561

vector<vector<int>> devise_strategy(int n) {
  vector<vector<int>> ans;
  vector<vector<int>> digits(n);
  for (int i = 0; i < n; i++)
  {
    for (int j = 0, x = i; j < POWER; j++)
    {
      digits[i].push_back(x % BASE);
      x /= BASE;
    }
    reverse(begin(digits[i]), end(digits[i]));
  }

  // 0
  {
    vector<int> a = {0};
    for (int j = 0; j < n; j++)
      a.push_back(digits[j][0] + 1);
    ans.push_back(a);
  }

  // [1, 21]
  for (int i = 0; i < POWER - 1; i++)
    for (int x = 0; x < BASE; x++)
    {
      int otherBag = i % 2, curBag = otherBag ^ 1;
      vector<int> a = {curBag};
      for (int j = 0; j < n; j++)
        if (digits[j][i] < x) a.push_back(-curBag - 1);
        else if (digits[j][i] > x) a.push_back(-otherBag - 1);
        else if (i < POWER - 2) a.push_back((i + 1) * BASE + digits[j][i + 1] + 1);
        else // last digit
        {
          if (digits[j][i + 1] == 0) a.push_back(-curBag - 1);
          else if (digits[j][i + 1] == 2) a.push_back(-otherBag - 1);
          else a.push_back((i + 1) * BASE + 1);
        }

      ans.push_back(a);
    }

  // 22
  {
    int curBag = 0, otherBag = 1;
    vector<int> a = {curBag};
    for (int j = 0; j < n; j++)
      if (digits[j][POWER - 1]) a.push_back(-otherBag - 1);
      else a.push_back(-curBag - 1);
    ans.push_back(a);
  }

  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...