結果

問題 No.966 引き算をして門松列(その1)
ユーザー mikianaaamikianaaa
提出日時 2020-09-03 20:12:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,404 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 164,620 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 16:20:50
合計ジャッジ時間 2,428 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int T;
    cin >> T;
    rep(i, T) {
        ll A, B, C;
        cin >> A >> B >> C;
        ll ans = INF;
        if (B == 0) {
            cout << -1 << endl;
        } else if ((B > A && B > C) || (B < A && B < C)) {
            if (A != C) {
                cout << 0 << endl;
            } else if (A == 1) {
                cout << -1 << endl;
            } else {
                cout << 1 << endl;
            }
        } else {
            ll tmp = 0;
            bool j = 0;
            if (A == C)
                A--, j = 1, tmp = 1;
            // B最小化
            ll mi = min(A, C) - 1;
            if (mi > 0)
                tmp += B - mi, ans = min(ans, tmp);
            // B最大化
            tmp = 0;
            if (j)
                tmp = 1;
            ll a, c;
            if (A > C)
                a = B - 2, c = A - 1;
            else
                a = B - 1, c = A - 2;
            if (a > 0 && c > 0)
                tmp += (A - a) + (C - c), ans = min(ans, tmp);
            cout << (ans == INF ? -1 : ans) << endl;
        }
    }
}
0