/ SeriousOJ /

Record Detail

Memory Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 2ms 328.0 KiB
#3 Memory Exceeded ≥546ms ≥256.016 MiB
#4 Memory Exceeded ≥546ms ≥256.016 MiB

Code

#include <bits/stdc++.h>
#define int long long
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 LONG_LONG_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:51:24
Judged At
2024-11-11 03:37:58
Judged By
Score
40
Total Time
≥546ms
Peak Memory
≥256.016 MiB