結果

問題 No.1440 The Quiz Competition
ユーザー KKT89KKT89
提出日時 2021-03-26 22:08:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,567 bytes
コンパイル時間 2,718 ms
コンパイル使用メモリ 202,296 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-06 15:42:50
合計ジャッジ時間 6,687 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 3 ms
6,944 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
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 <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int q; cin >> q;
	while(q--){
		ll n,a,w,k; cin >> n >> a >> w >> k;
		if(k==1){ // 多分OK
			if(a)printf("%lld\n",a);
			else{
				if(w<n-1){
					printf(":(\n");
				}
				else{
					printf("0\n");
				}
			}
		}
		else if(n==k){ 
			if(w==0){ // ここも多分OK
				if(a<n-1){
					printf(":(\n");
				}
				else{
					printf("0\n");
				}
			}
			else{
				// ここ確実にダメだ
				// とりあえずsubmitデバッグ
				assert(0);
				ll L=-1,R=w; // 最下位が不正解する回数
				while(R-L>1){
					ll mid=(L+R)/2;
					ll tmp=(w-mid)/(n-1);
					ll m=tmp*(tmp+1)/2*(n-1);
					ll u=w-tmp-tmp*(n-1);
					ll uu=(n-1)-u;
					ll aa=((mid*(mid+1)/2-1)>=m+(tmp+1)?0:(mid*(mid+1)/2-1)-m-(tmp+1));
					aa*=u;
					ll aaa=((mid*(mid+1)/2-1)>=m?0:(mid*(mid+1)/2-1)-m);
					aaa*=uu;
					if(aa+aaa<=a){
						R=mid;
					}
					else{
						L=mid;
					}
				}
				printf("%lld\n",-R*(R+1)/2);
			}
		}
		else{
			if(a==0){ // ここもOK
				if(w>=1+(n-k)){
					printf("-1\n");
				}
				else{
					printf(":(\n");
				}
			}
			else if(k-1<=a){ // ここも多分OKなはず…
				ll L=0,R=2e9;
				while(R-L>1){
					ll mid=(L+R)/2;
					if((k-1)*(mid+1)+mid<=a)L=mid;
					else R=mid;
				}
				printf("%lld\n",L);
			}
			else{
				assert(0);
			}
		}
	}
}
0