結果

問題 No.1440 The Quiz Competition
ユーザー SSRSSSRS
提出日時 2021-03-26 23:00:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,002 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 164,632 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-19 09:43:22
合計ジャッジ時間 3,098 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int N, A, W, K;
    cin >> N >> A >> W >> K;
    if (K != N || W == 0){
      if (A < K - 1){
        if (W >= N - K + 1){
          cout << -1 << endl;
        } else {
          cout << ":(" << endl;
        }
      } else if (A % K == K - 1){
        cout << A / K << endl;
      } else {
        cout << A / K - 1 << endl;
      }
    } else {
      long long sum = A - (long long) W * (W + 1) / 2;
      int r = (sum % N + N) % N;
      long long q = (sum - r) / N;
      if (r != N - 1){
        q--;
      }
      long long fv = 0, tv = W + 1;
      while (tv - fv > 1){
        long long mid = (tv + fv) / 2;
        if (- mid * (mid + 1) / 2 <= q){
          tv = mid;
        } else {
          fv = mid;
        }
      }
      long long s = - tv * (tv + 1) / 2;
      if (s + A > q){
        cout << q << endl;
      } else {
        cout << s + A << endl;
      }
    }
  }
}
0