結果
問題 |
No.1440 The Quiz Competition
|
ユーザー |
![]() |
提出日時 | 2021-03-26 23:08:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,245 bytes |
コンパイル時間 | 4,209 ms |
コンパイル使用メモリ | 249,688 KB |
最終ジャッジ日時 | 2025-01-19 23:29:03 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 2 RE * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:26:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | scanf("%lld %lld %lld %lld",&N,&A,&W,&K); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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; }