Submission #1002193

#TimeUsernameProblemLanguageResultExecution timeMemory
1002193werty783Prisoner Challenge (IOI22_prison)C++17
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
#include <string>

using namespace std;

string to_ternary(int a) {
    int converted = 0;
    int multiplier = 1;

    int reszta;
    while (a > 1) {
        reszta = a % 3;
        converted += reszta * multiplier;
        multiplier *= 10;
        a = floor((a+0.25)/3);
    }
    
    return to_string(converted);
}

int policz(int tab, int kwota) {
    int a = 0; int b = 5000; int poziom;

    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;
    for (int i = 0; i < 22; i++) {
        for (int j = 0; j < N; j++) {
            strategy[i].push_back(policz(i, j));
        }
    }
    return (strategy);
} 

Compilation message (stderr)

prison.cpp: In function 'std::string to_ternary(int)':
prison.cpp:16:13: error: 'floor' was not declared in this scope
   16 |         a = floor((a+0.25)/3);
      |             ^~~~~
prison.cpp: In function 'int policz(int, int)':
prison.cpp:23:9: warning: unused variable 'a' [-Wunused-variable]
   23 |     int a = 0; int b = 5000; int poziom;
      |         ^
prison.cpp:23:20: warning: unused variable 'b' [-Wunused-variable]
   23 |     int a = 0; int b = 5000; int poziom;
      |                    ^
prison.cpp:23:34: warning: unused variable 'poziom' [-Wunused-variable]
   23 |     int a = 0; int b = 5000; int poziom;
      |                                  ^~~~~~