/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 400.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 2ms 320.0 KiB
#4 Accepted 2ms 320.0 KiB
#5 Accepted 3ms 576.0 KiB
#6 Accepted 11ms 604.0 KiB
#7 Accepted 98ms 1.793 MiB
#8 Accepted 94ms 1.52 MiB
#9 Accepted 93ms 1.652 MiB
#10 Accepted 92ms 2.234 MiB
#11 Accepted 94ms 2.074 MiB

Code

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using ll = long long;

ll get_ans(ll n, ll k) {
  ll i, t, l, r, mid1, mid2, ans1, ans2, ans;

  l = 0; r = (k+n-1)/n;
  t = 100; while (t--) {
    mid1 = l + (r-l)/3;
    mid2 = r - (r-l)/3;
    ans1 = mid1 * (k - mid1*n);
    ans2 = mid2 * (k - mid2*n);
    if (ans1 > ans2) {
      r = mid2;
    } else {
      l = mid1;
    }
  }

  ans = 0;
  for (i = l; i <= r; ++i) {
    ans = max(ans, i * (k - i*n));
  }

  return ans;
}

int main() {
  FAST;
  
  int tc = 1, ti;
  cin >> tc;

  for (ti = 1; ti <= tc; ++ti) {
    ll n, k;
    cin >> n >> k;
    cout << get_ans(n, k) << "\n";
  }

  return 0;
}

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:39:23
Judged At
2024-11-11 02:59:53
Judged By
Score
100
Total Time
98ms
Peak Memory
2.234 MiB