Submission details
Task:Lukujono
Sender:sharph2
Submission time:2025-11-28 21:53:03 +0200
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.03 sdetails
#2ACCEPTED0.03 sdetails
#3ACCEPTED0.03 sdetails

Code

#include <climits>
#include <cstdint>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

vector<int> M;

int ratko(int x) {
    if(x < 1) {
        throw 5;
    }
    if(x % 3 == 2) {
        return -1;
    }
    if(x == 1) {
        return 1;
    }
    if((int)M.size() <= x) {
        M.resize(x + 1);
    }
    if(M[x] == 0) {
        M[x] = -1;
        int y;
        if(x % 3 == 0) {
            y = x / 3;
        } else {
            y = 2 * x + 1;
        }
        M[x] = ratko(y);
        if(M[x] != -1) {
            ++M[x];
        }
    }
    return M[x];
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    for(int i = 1; i <= 1000000; ++i) {
        ratko(i);
    }

    int t;
    cin >> t;

    for(int i = 0; i < t; ++i) {
        int x;
        cin >> x;
        cout << ratko(x) << "\n";
    }

    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
1000
1
2
3
4
...

correct output
1
-1
2
4
-1
...

user output
1
-1
2
4
-1
...

Test 2

Verdict: ACCEPTED

input
1000
152435
165584
587562
428318
...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 3

Verdict: ACCEPTED

input
1000
235119
235120
235144
236196
...

correct output
27
27
27
14
27
...

user output
27
27
27
14
27
...