이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
// 0 : not seen A
// 1 : seen A, num = 0
// 2 : seen A, num = 1
vector<vector<int>> devise_strategy(int N) {
int h = __lg(N);
int sz = 3 * (h + 1);
vector<vector<int>> choose(sz, vector<int>(N + 1));
FOR (state, 0, sz - 1) {
int times = state / 3;
int cur = state % 3;
if (cur == 0) choose[state][0] = 0;
else choose[state][0] = 1;
FOR (i, 1, N) {
int bit = i >> (h - times) & 1;
if (cur == 0) choose[state][i] = state + bit + 1;
else {
if (cur - 1 == bit) choose[state][i] = 3 * (times + 1);
else {
if (cur - 1 == 0) 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
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |