/ SeriousOJ /

Record Detail

Memory Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Memory Exceeded ≥2099ms ≥256.016 MiB
#4 Memory Exceeded ≥2102ms ≥256.016 MiB

Code

#include <bits/stdc++.h>
using namespace std;

int koro(int A, int B) {
    queue<pair<int, int>> q;
    q.push({A, 0});

    while (!q.empty()) {
        pair<int, int> front = q.front();
        q.pop();
        int num = front.first;
        int dorkar = front.second;

        if (num == B)
            return dorkar;
        if (num * 2 <= B)
            q.push({num * 2, dorkar + 1});

        if (num + 1 <= B)
            q.push({num + 1, dorkar + 1});
    }

    return INT_MAX;
}

int32_t main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int T;
    cin >> T;

    while (T--) {
        int A, B;
        cin >> A >> B;
        cout << koro(A, B) << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1044 Add or multiple
Contest
TLE_Headquarters - round #1
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-27 16:52:07
Judged At
2024-11-11 03:37:57
Judged By
Score
40
Total Time
≥2102ms
Peak Memory
≥256.016 MiB