結果

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

テストケース

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

ソースコード

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;
            ll l1=-1, r1=2e9;
            while(r1-l1>1){
                ll m1=(l1+r1)/2;
                if(m1*(m1+1)/2>=-m){
                    r1=m1;
                }else{
                    l1=m1;
                }
            }
            if(r1*(r1+1)/2+m>a){
                r1--;
                if(r1<0){
                    r=m;
                    continue;
                }
            }
            r1=min(r1, w);
            ll a1, x1;
            if(-r1*(r1+1)/2>=m){
                a1=a;
                x1=-r1*(r1+1)/2+1;
            }else{
                a1=a-(m+r1*(r1+1)/2);
                x1=m+1;
            }
            ll w1=w-r1;
            ll p=w1%(n-1);
            ll q=w1/(n-1);
            lll s=(lll)max(0ll, x1+(q+1)*(q+2)/2)*p+(lll)max(0ll, x1+(q+1)*q/2)*(n-1-p);
            if(s<=a1) l=m;
            else r=m;
        }
        cout<<l<<endl;
    }
    return 0;
}
0