제출 #825154

#제출 시각아이디문제언어결과실행 시간메모리
825154becaido죄수들의 도전 (IOI22_prison)C++17
0 / 100
1 ms212 KiB
#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; 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(5000) / log(B); int sz = B * (h + 1); vector<vector<int>> choose(sz + 1, vector<int>(N + 1)); FOR (state, 0, sz) { if (state == 0) { choose[state][0] = 0; FOR (i, 1, N) { int bit = cal(i, h); choose[state][i] = B + bit - 1; } continue; } int times = (state + 1) / B; int cur = (state + 1) % B; choose[state][0] = times & 1; FOR (i, 1, N) { int bit = cal(i, h - times + 1); if (cur != bit) choose[state][i] = ((cur < bit) ^ (times & 1)) ? -2 : -1; else { bit = cal(i, h - times); choose[state][i] = B * (times + 1) + bit - 1; } } } FOR (i, 0, sz) FOR (j, 0, N) { choose[i][j] = min(choose[i][j], sz); } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...