結果

問題 No.1440 The Quiz Competition
ユーザー chocoruskchocorusk
提出日時 2021-04-01 05:49:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,428 bytes
コンパイル時間 3,335 ms
コンパイル使用メモリ 187,896 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 11:11:36
合計ジャッジ時間 4,528 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
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 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int t; cin>>t;
    while(t--){
        ll n, a, w, k;
        cin>>n>>a>>w>>k;
        if(k<n){
            if(a>=k-1){
                cout<<(a-(k-1))/k<<endl;
            }else if(w>=n-(k-1)){
                cout<<-1<<endl;
            }else{
                cout<<":("<<endl;
            }
            continue;
        }
        if(w==0 && a<n-1){
            cout<<":("<<endl;
            continue;
        }
        using lll=__int128_t;
        ll l=-1e18, r=1e9;
        while(r-l>1){
            ll m=(l+r)/2;
            bool ok=0;
            ll p=w%n, q=w/n;
            if(p==0){
                if(-q*(q+1)/2>=m){
                    if(a>=n-1) ok=1;
                }else{
                    ll s=(m+q*(q+1)/2)+(m+q*(q+1)/2+1)*(n-1);
                    if(a>=s) ok=1;
                }
                if(w!=0){
                    if(-(q+2)*(q+1)/2>=m){
                        ok=1;
                    }else{
                        ll s=(m+(q+2)*(q+1)/2)+max(0ll, m+q*(q+1)/2+1)*(n-2)+max(0ll, m+q*(q-1)/2+1);
                        if(a>=s) ok=1;
                    }
                }
            }else{
                if(-(q+2)*(q+1)/2>=m){
                    ok=1;
                }else{
                    ll s=(m+(q+2)*(q+1)/2)+max(0ll, m+(q+2)*(q+1)/2+1)*(p-1)+max(0ll, m+q*(q+1)/2+1)*(n-p);
                    if(a>=s) ok=1;
                }
                if(p!=1){
                    if(-(q+2)*(q+3)/2>=m){
                        ok=1;
                    }else{
                        ll s=(m+(q+2)*(q+3)/2)+max(0ll, m+(q+2)*(q+1)/2+1)*(p-1)+max(0ll, m+q*(q+1)/2+1)*(n-p);
                        if(a>=s) ok=1;
                    }
                }
            }
            if(ok) l=m;
            else r=m;
        }
        cout<<l<<endl;
    }
    return 0;
}
0