結果

問題 No.1440 The Quiz Competition
ユーザー first_vilfirst_vil
提出日時 2021-01-03 14:58:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,566 bytes
コンパイル時間 6,884 ms
コンパイル使用メモリ 306,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 12:58:50
合計ジャッジ時間 7,990 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

#include "testlib.h"
int main() {
    init();
    registerValidation();

    int t = inf.readInt(1, 100);
    inf.readEoln();

    ll n_sum = 0;
    while (t--) {
        ll n = inf.readInt(2, 200000);
        inf.readSpace();
        n_sum += n;

        ll a = inf.readInt(0, 1000000000);
        inf.readSpace();
        ll w = inf.readInt(0, 1000000000);
        inf.readSpace();
        ll k = inf.readInt(1, n);
        inf.readEoln();

        if (a < k - 1 && w < n - k + 1) {
            cout << ":(\n";
            continue;
        }

        ll ans;
        if (k == n) {
            ll c = (w + n - 1) / n, f = w / n;
            ll x = w % n, y = n - x;
            ll xw = -c * (c + 1) / 2, yw = -f * (f + 1) / 2;
            if (x == 0) {
                if (a < n - 1)ans = min(yw - (f + 1) + a, yw - 1);
                else ans = yw + (a - (n - 1)) / n;
            }
            else {
                if (a < x - 1)ans = min(xw - (c + 1) + a, xw - 1);
                else {
                    if (a <= c * x - 1)ans = xw + (a - (x - 1)) / x;
                    else ans = yw - 1 + (a - (c * x - 1)) / n;
                }
            }
        }
        else {
            if (a < k - 1)ans = -1;
            else ans = (a - (k - 1)) / k;
        }
        cout << ans << "\n";
    }

    assert(n_sum <= 200000);
    inf.readEof();

    return 0;
}
0