This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "prison.h"
#include <vector>
#include <iostream>
int get_bit_value(int num, int bit_id) {
if (bit_id < 0) {
return 0;
}
if (bit_id == 0) {
return num % 2;
}
return get_bit_value(num / 2, bit_id - 1);
}
int get_maximal_bit_id(int num) {
if (num < 2) {
return 0;
}
return 1 + get_maximal_bit_id(num / 2);
}
std::vector<std::vector<int>> devise_strategy3(int N) {
int x = (get_maximal_bit_id(N) + 2) * 3;
x = 38;
std::vector<std::vector<int>> s(x + 1, std::vector<int>(N + 1));
for (int i = 0; i <= x; i++) {
for (int j = 0; j <= N; j++) {
s[i][j] = 0;
}
}
for (int i = 0; i <= x; i++) {
if (i % 3 == 0) {
s[i][0] = 0;
}
else {
s[i][0] = 1;
}
}
int bit_id = get_maximal_bit_id(N);
for (int i = 0; i <= x; i++) {
bool looking_at_a = false;
if (i % 3 == 0) {
looking_at_a = true;
if (i != 0) {
bit_id -= 1;
}
}
for (int j = 1; j <= N; j++) {
int cur_bit_value = get_bit_value(j, bit_id);
if (looking_at_a) {
s[i][j] = i + 1 + cur_bit_value;
}
else {
int last_bit_value = (i % 3) - 1;
if (last_bit_value != cur_bit_value) {
if (last_bit_value > cur_bit_value) {
s[i][j] = -2;
}
else {
s[i][j] = -1;
}
}
else {
s[i][j] = i + 1;
if (i % 3 == 1) {
s[i][j] += 1;
}
}
}
}
}
for (int i = 0; i <= x; i++) {
for (int j = 1; j <= N; j++) {
if (s[i][j] > x) {
s[i][j] = x;
}
}
}
return s;
}
std::vector<std::vector<int>> devise_strategy(int N) {
int x = (get_maximal_bit_id(N) + 2) * 3;
x = 26;
std::vector<std::vector<int>> s(x + 1, std::vector<int>(N + 1));
for (int i = 0; i <= x; i++) {
for (int j = 0; j <= N; j++) {
s[i][j] = 0;
}
}
bool look_at_a = true;
for (int i = 0; i <= x; i++) {
if (i % 2 == 1) {
look_at_a = !look_at_a;
}
if (look_at_a) {
s[i][0] = 0;
}
else {
s[i][0] = 1;
}
}
int bit_id = get_maximal_bit_id(N);
bool looking_at_a = true;
for (int i = 0; i <= x; i++) {
if (i % 2 == 1) {
looking_at_a = !looking_at_a;
if (i != 1) {
bit_id -= 1;
}
}
for (int j = 1; j <= N; j++) {
int cur_bit_value = get_bit_value(j, bit_id);
if (i == 0) {
if (cur_bit_value == 0) {
s[i][j] = 1;
}
else {
s[i][j] = 2;
}
}
else {
int last_bit_value = 1 - (i % 2);
if (last_bit_value != cur_bit_value) {
if (last_bit_value > cur_bit_value) {
if (looking_at_a) {
s[i][j] = -1;
}
else {
s[i][j] = -2;
}
}
else {
if (looking_at_a) {
s[i][j] = -2;
}
else {
s[i][j] = -1;
}
}
}
else {
int next_bit_value = get_bit_value(j, bit_id - 1);
s[i][j] = i + 1 + (i % 2);
if (next_bit_value == 1) {
s[i][j] += 1;
}
}
}
}
}
for (int i = 0; i <= x; i++) {
for (int j = 1; j <= N; j++) {
if (s[i][j] > x) {
s[i][j] = x;
}
}
}
return s;
}
std::vector<std::vector<int>> devise_strategy2(int N) {
std::vector<std::vector<int>> s(N + 1, std::vector<int>(N + 1));
s[0][0] = 0;
for (int i = 1; i <= N; i++) {
s[i][0] = 1;
}
for (int i = 1; i <= N; i++) {
s[0][i] = i;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (i <= j) {
s[i][j] = -1;
}
else {
s[i][j] = -2;
}
}
}
return s;
}
bool solution(std::vector<std::vector<int>> s, int a, int b) {
int value_on_board = 0;
while (true) {
int num = -1;
if (s[value_on_board][0] == 0) {
num = a;
}
else if (s[value_on_board][0] == 1) {
num = b;
}
else {
std::cout << "major problem!!";
}
if (s[value_on_board][num] == -1) {
//std::cout << "a is lower" << std::endl;
return false;
}
else if (s[value_on_board][num] == -2) {
//std::cout << "b is lower" << std::endl;
return true;
}
else {
value_on_board = s[value_on_board][num];
}
}
}
/*int main() {
int n = 5000;
std::vector<std::vector<int>> s = devise_strategy(n);
std::vector<std::vector<int>> s2 = devise_strategy2(n);
std::cout << solution(s, 32, 64) << std::endl;
std::cout << solution(s2, 32, 64) << std::endl;
//for (int a = 1; a <= n; a++) {
//std::cout << "Here " << a << std::endl;
//for (int b = 1; b <= n; b++) {
// if (a == b) {
// continue;
// }
//if (solution(s, a, b) != solution(s2, a, b)) {
// std::cout << "problem " << a << " " << b << std::endl;
//}
//}
//}
std::cout << s.size() << std::endl;
std::cout << solution(s, 105, 100) << std::endl;
std::cout << solution(s2, 105, 100) << std::endl;
//for (int a = 1; a <= n; a++) {
//std::cout << a << std::endl;
//for (int b = 1; b <= n; b++) {
//if (a == b) {
//continue;
//}
//bool res = solution(s, a, b);
//bool real_res = a > b;
//if (res != real_res) {
//std::cout << " major problem" << std::endl;
//}
//}
//}
std::cout << "cool" << std::endl;
}//*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |