Submission #1002295

#TimeUsernameProblemLanguageResultExecution timeMemory
1002295werty783Prisoner Challenge (IOI22_prison)C++17
0 / 100
1 ms432 KiB
#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; if (idx_to_compare == -1) { idx_to_compare = 0; } // 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]; // cout << char_to_compare << endl; int kwota_to_compare = char_to_compare - '0'; // cout << kwota_to_compare << endl; if (deciphered_tab == 0) { int result = 10*kwota_to_compare + 1; // cout << result << endl; return cipher[result]; } if (idx_to_compare == 7) { if (kwota_to_compare == 2) { if (bag == 0) { chosen_bag = -2; } else { chosen_bag = -1; } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...