Submission #824830

# Submission time Handle Problem Language Result Execution time Memory
824830 2023-08-14T10:59:39 Z becaido Radio Towers (IOI22_towers) C++17
Compilation error
0 ms 0 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifndef WAIMAI
#include "prison.h"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int K = 500;
const int B = 3;

// 0 : not seen A
// 1 : seen A, num = 0
// 2 : seen A, num = 1

int cal(int x, int k) {
    FOR (i, 1, k) x /= B;
    return x % B;
}

vector<vector<int>> devise_strategy(int N) {
    int h = log(N) / log(B);
    int sz = (B + 1) * (h + 1);
    vector<vector<int>> choose(sz, vector<int>(N + 1));
    FOR (state, 0, sz - 1) {
        int times = state / (B + 1);
        int cur = state % (B + 1);
        if (cur == 0) choose[state][0] = 0;
        else choose[state][0] = 1;
        FOR (i, 1, N) {
            int bit = cal(i, h - times);
            if (cur == 0) choose[state][i] = state + bit + 1;
            else {
                if (cur - 1 == bit) choose[state][i] = (B + 1) * (times + 1);
                else {
                    if (cur - 1 < bit) choose[state][i] = -1;
                    else choose[state][i] = -2;
                }
            }
        }
    }
    FOR (i, 0, sz - 1) FOR (j, 0, N) choose[i][j] = min(choose[i][j], sz - 1);
    return choose;
}

/*
in1
3
1 2
1 3
2 1
2 3
3 1
3 2
-1
out1
A
A
B
A
B
B
*/

#ifdef WAIMAI
static constexpr int kNumPrisoners = 500;

static void invalid_strategy(string message) {
  printf("%s\n", message.c_str());
  exit(0);
}

int main() {
  int N;
  assert(1 == scanf("%d", &N));

  vector<vector<int>> strategy = devise_strategy(N);
  if (strategy.size() == 0) {
    invalid_strategy("s is an empty array");
  }
  int x = strategy.size() - 1;
  for (int i = 0; i <= x; ++i) {
    if (static_cast<int>(strategy[i].size()) != N + 1) {
      invalid_strategy("s[i] contains incorrect length");
    }
    if (strategy[i][0] < 0 || strategy[i][0] > 1) {
      invalid_strategy("First element of s[i] is non-binary");
    }
    for (int j = 1; j <= N; ++j) {
      if (strategy[i][j] < -2 || strategy[i][j] > x) {
        invalid_strategy("s[i][j] contains incorrect value");
      }
    }
  }

  FILE *log_file = fopen("log.txt","w");

  int A, B;
  while (1 == scanf("%d", &A) && A != -1) {
    assert(1 == scanf("%d", &B));
    bool answer = false;
    int whiteboard = 0;
    for (int i = 0; i < kNumPrisoners && !answer; ++i) {
      int check = strategy[whiteboard][0];
      whiteboard = strategy[whiteboard][check == 0 ? A : B];
      if (whiteboard < 0) {
        answer = true;
        printf("%c\n", "BA"[whiteboard + 2]);
      } else {
        if (i > 0) {
          fprintf(log_file, " ");
        }
        fprintf(log_file, "%d", whiteboard);
      }
    }
    if (!answer) {
      printf("X\n");
    }
    fprintf(log_file, "\n");
    fflush(log_file);
  }
}
#endif

Compilation message

towers.cpp:7:10: fatal error: prison.h: No such file or directory
    7 | #include "prison.h"
      |          ^~~~~~~~~~
compilation terminated.