/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 344.0 KiB
#3 Wrong Answer 2ms 580.0 KiB
#4 Wrong Answer 2ms 564.0 KiB
#5 Wrong Answer 2ms 536.0 KiB
#6 Wrong Answer 5ms 532.0 KiB
#7 Wrong Answer 36ms 1.344 MiB
#8 Wrong Answer 32ms 1.262 MiB
#9 Wrong Answer 36ms 1.441 MiB
#10 Wrong Answer 37ms 732.0 KiB
#11 Wrong Answer 39ms 1.359 MiB

Code

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
#define sz(x) (ll)(x).size()
#define rd ({ll x; cin >> x; x; })
#define dbg(x) cerr << "[" #x "]  " << (x) << "\n\n"
// #define errv(x) {cerr << "["#x"]  ["; for (const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
// #define errvn(x, n) {cerr << "["#x"]  ["; for (auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
// #define cerr if(0)cerr
#define xx first
#define yy second
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
/*_________________________________________________________________________________________________________________________*/

void Solve()
{
    ll a, b;
    cin >> a >> b;
    if (b <= a) {
        cout << 0 << '\n';
        return;
    }
    ll lo = 1, hi = b / a, ans = 0;
    while (lo <= hi) {
        ll mid1 = lo + (hi - lo) / 3;
        ll mid2 = hi - (hi - lo) / 3;
        ll ans1 = mid1 * (b - a * mid1);
        ll ans2 = mid2 * (b - a * mid2);
        if (ans1 == ans2) {
            ans = ans1;
            lo = mid1 + 1;
            hi = mid2 - 1;
        } else if (ans1 > ans2) {
            ans = ans1;
            lo = mid1 + 1;
        } else {
            ans = ans2;
            hi = mid2 - 1;
        }
    }
    cout << ans << '\n';
}

int32_t main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": "; // cout << "Case " << i << ": ";
        Solve();
    }
    return 0;
}
// Coded by Tahsin Arafat (@TahsinArafat)

Information

Submit By
Type
Submission
Problem
P1092 Bitwise AND
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 16:08:51
Judged At
2024-10-03 13:08:48
Judged By
Score
1
Total Time
39ms
Peak Memory
1.441 MiB