結果
問題 | No.1440 The Quiz Competition |
ユーザー | ocvret_ |
提出日時 | 2021-03-26 22:50:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,012 bytes |
コンパイル時間 | 1,509 ms |
コンパイル使用メモリ | 169,292 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-05-06 16:44:09 |
合計ジャッジ時間 | 2,409 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 1 ms
6,940 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 | - |
ソースコード
#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--){ int 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){ ll l = 0,r = A+1; ll res = -1ll*MOD*MOD; while(r-l > 1){ ll mid = (l+r)/2; ll mn = (A-mid)/(n-1),mx = (A-mid+n-2)/(n-1); ll l2 = -1,r2 = W; while(r2-l2 > 1){ ll mid2 = (l2 + r2)/2; ll k = W - mid2; ll 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; } ll k = W - r2; ll 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; } } ll l2 = -1,r2 = W; ll mn = (A-l)/(n-1),mx = (A-l+n-2)/(n-1); while(r2-l2 > 1){ ll mid2 = (l2 + r2)/2; ll k = W - mid2; ll 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; } res = max(res,l - r2*(r2+1)/2); if(res != -1ll*MOD*MOD)cout << res << "\n"; else cout << ":(\n"; } } return 0; }