結果

問題 No.1440 The Quiz Competition
ユーザー ocvret_ocvret_
提出日時 2021-03-26 23:06:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,268 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 167,800 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 09:51:25
合計ジャッジ時間 3,051 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int T;
  cin >> T;
  while(T--){
    ll n,A,W,K;
    cin >> n >> A >> W >> K;
    if(K != n && K != 1){
      ll l = -1,r = MOD;
      while(r-l > 1){
        ll mid = (l+r)/2;
        bool ok = true;
        if((mid+1)*(K-1) + mid > A)ok = false;
        if(ok)l = mid;
        else r = mid;
      }
      if(l == -1){
        if(W >= n - K + 1)l = -1;
        else l = -MOD;
      }

      if(l != -MOD)cout << l << "\n";
      else cout << ":(\n";

    }else if(K == 1){
      cout << A << "\n";
    }else if(K == n){
      __int128_t l = 0,r = A+1;
      __int128_t res = -1ll*MOD*MOD;
      while(r-l > 1){
        __int128_t mid = (l+r)/2;
        __int128_t mn = (A-mid)/(n-1),mx = (A-mid+n-2)/(n-1);
        __int128_t l2 = -1,r2 = W;
        while(r2-l2 > 1){
          __int128_t mid2 = (l2 + r2)/2;
          __int128_t k = W - mid2;
          __int128_t s = k/(n-1),t = (k+n-2)/(n-1);
          if(mid - mid2*(mid2+1)/2 < min(mn - s*(s+1)/2,mx - t*(t+1)/2))r2 = mid2;
          else l2 = mid2;
        }
        __int128_t k = W - r2;
        __int128_t s = k/(n-1),t = (k+n-2)/(n-1);
          
        if(mid - r2*(r2+1)/2 < min(mn - s*(s+1)/2,mx - t*(t+1)/2)){
          l = mid;
        }else{
          r = mid;
        }

      }
      __int128_t l2 = -1,r2 = W;
      __int128_t mn = (A-l)/(n-1),mx = (A-l+n-2)/(n-1);
      while(r2-l2 > 1){
        __int128_t mid2 = (l2 + r2)/2;
        __int128_t k = W - mid2;
        __int128_t s = k/(n-1),t = (k+n-2)/(n-1);
        if(l - mid2*(mid2+1)/2 < min(mn - s*(s+1)/2,mx - t*(t+1)/2))r2 = mid2;
        else l2 = mid2;
      }
      __int128_t k = W - r2;
      __int128_t s = k/(n-1),t = (k+n-2)/(n-1);
      if(l - r2*(r2+1)/2 < min(mn - s*(s+1)/2,mx - t*(t+1)/2))res = max(res,l - r2*(r2+1)/2);
      if(res != -1ll*MOD*MOD)cout << ll(res) << "\n";
      else cout << ":(\n";
    }
  }


  return 0;
}
0