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 <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
string to_ternary(int a) {
if (a == 0)
return "0"; // Special case for zero
string ternary = ""; // Initialize an empty string for ternary representation
while (a != 0) {
int remainder = a % 3;
ternary = to_string(remainder) + ternary; // Build the ternary string in reverse order
a = floor(a / 3); // Integer division by 3
}
return ternary;
}
int policz(int tab, int kwota) {
int decipher[28] = {0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17, 18, 21, 22, 23, 24, 25, 26, 27};
int cipher[28] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 8, 9, 10, 11, 12, 13, 14, 15, 0, 0, 16, 17, 18, 19, 20, 21, 22};
int deciphered_tab = decipher[tab];
// cout << deciphered_tab << '\n';
if (kwota == 0) {
if (deciphered_tab % 2 == 0) {return 0;} else {return 1;}
} else {
int bag = 0 ? (deciphered_tab % 2 == 0) : 1;
int chosen_bag = 0;
string kwota_in_ternary = to_ternary(kwota);
int idx_to_compare = (deciphered_tab % 10) - 1;
// cout << idx_to_compare << endl;
int value_to_compare = ((deciphered_tab/10) % 10);
// cout << value_to_compare << endl;
// cout << kwota_in_ternary[idx_to_compare] << endl;
char char_to_compare = kwota_in_ternary[idx_to_compare];
int kwota_to_compare = char_to_compare - '0';
if (idx_to_compare == 7) {
if (kwota_to_compare == 2) {
if (bag == 0) {
chosen_bag = -1;
} else {
chosen_bag = -2;
}
return chosen_bag;
} else if (kwota_to_compare == 0) {
if (bag == 0) {
chosen_bag = -1;
} else {
chosen_bag = -2;
}
return chosen_bag;
} else {
return cipher[18];
}
}
if (kwota_to_compare > value_to_compare) {
if (bag == 0) {
chosen_bag = -2;
} else {
chosen_bag = -1;
}
return chosen_bag;
} else if (kwota_to_compare < value_to_compare) {
if (bag == 0) {
chosen_bag = -1;
} else {
chosen_bag = -2;
}
return chosen_bag;
} else {
char next_kwota_char = kwota_in_ternary[idx_to_compare+1];
int next_kwota_int = next_kwota_char - '0';
int result = 10*next_kwota_int + idx_to_compare + 2;
return cipher[result];
}
}
}
vector<vector<int>> devise_strategy(int N) {
vector<vector<int>> strategy(23, vector<int>(N)); // Initialize strategy with 23 vectors of size N
for (int i = 0; i < 23; i++) {
for (int j = 0; j < N; j++) {
strategy[i][j] = policz(i, j);
}
}
return strategy;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |