結果

問題 No.1440 The Quiz Competition
ユーザー 沙耶花沙耶花
提出日時 2021-03-26 23:08:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,245 bytes
コンパイル時間 4,822 ms
コンパイル使用メモリ 260,128 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-19 09:55:34
合計ジャッジ時間 9,959 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

long long get(long long n){
	return n*(n+1)/2;
}

long long get(long long n,long long w){
	return get(w/n)*n + (w%n)*(w/n+1);	
}

int main(){
	
	int _t;
	cin>>_t;
	
	rep(_,_t){
		
		long long N,A,W,K;
		scanf("%lld %lld %lld %lld",&N,&A,&W,&K);
		
		long long ok = -1,ng = Inf;
		while(ng-ok>1){
			long long mid = (ok+ng)/2;
			
			long long cur = A;
			cur -= (mid+1) * (K-1);
			cur -= mid;
			
			if(cur<0){
				ng = mid;
			}
			else if(K!=N){
				ok = mid;
			}
			else{
				cur -= get(N,W);
				if(cur<0)ng = mid;
				else ok = mid;
			}
			
		}
		if(ok!=-1){
			cout<<ok<<endl;
			continue;
		}
		
		if(K!=N){
			if(N-K<=W){
				cout<<-1<<endl;
			}
			else{
				cout<<":("<<endl;
			}
			continue;
		}
		else{
			if(W==0){
				cout<<":("<<endl;
				continue;
			}
			assert(false);
			long long ok = W+1,ng = 0;
			
			while(ok-ng>1){
				long long mid = (ok+ng)/2;
				long long cur = W;
				cur -= mid;
				
				
				if(cur<=0)ok = mid;
				else ng = mid;
				
			}
			cout<<ok<<endl;
			
		}
		
		
	}
	
    return 0;
}
0