제출 #1008394

#제출 시각아이디문제언어결과실행 시간메모리
1008394somefjord죄수들의 도전 (IOI22_prison)C++17
0 / 100
0 ms436 KiB
#include "prison.h" #include <bits/stdc++.h> using namespace std; int log2(int v) { int r = 0; while (v >>= 1) { r++; } return r; } int pack(int pos, int b, int ab) { return (pos << 3) | ((b & 1) << 2) | ((ab & 1) << 1) | 0b1; } vector<vector<int>> devise_strategy(int N) { int nbits = log2(N); int x = (nbits << 3) | 0b111; vector<vector<int>> s(x + 1, vector<int>(N + 1)); for (int pos = nbits; pos >= 0; --pos) { // previously inspected bit for (int b = 0; b <= 1; ++b) { // ab = 0 => bag a // ab = 1 => bag b // previously inspected for (int ab = 0; ab <= 1; ++ab) { int i = pack(pos, b, ab); // Inspect the other bag next s[i][0] = !ab; for (int v = 1; v <= N; ++v) { // printf("pos: %d b: %d ab: %d v: %d\n", pos, b, ab, v); bool selfset = (v >> pos) & 1; if (selfset && !b) { // if the bag we previously inspected did not have bit at pos set, // but we do s[i][v] = ab ? -2 : -1; } else if (!selfset && b) { // vice-versa s[i][v] = ab ? -1 : -2; } else if (pos != 0) { // move to a lesser significant bit s[i][v] = pack(pos - 1, selfset, !ab); } // printf(" s[%d][%d] = %d\n", i, v, s[i][v]); } } } } // whiteboard is always 0 initially, so inspect A s[0][0] = 0; for (int v = 1; v <= N; ++v) { bool selfset = (v >> nbits) & 1; s[0][v] = pack(nbits, selfset, 0); } return s; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...