結果

問題 No.966 引き算をして門松列(その1)
ユーザー merom686merom686
提出日時 2020-01-13 20:48:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 994 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 73,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:25:10
合計ジャッジ時間 1,207 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int f(int a, int b, int c) {
    int x = 0;
    if (a >= b) x += a - (b - 1), a = b - 1;
    if (c >= b) x += c - (b - 1), c = b - 1;
    if (a == c) x++, a--;
    if (a <= 0 || c <= 0) x = -1;
    return x;
}

int g(int a, int b, int c) {
    int x = 0;
    if (a == c) x++, a--;
    int t = min(a, c);
    if (b >= t) x += b - (t - 1), b = t - 1;
    if (a <= 0 || b <= 0) x = -1;
    return x;
}

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

    int t;
    cin >> t;

    for (int i = 0; i < t; i++) {
        int a, b, c;
        cin >> a >> b >> c;

        int x = f(a, b, c);
        int y = g(a, b, c);
        int r;
        if (x < 0 && y < 0) r = -1;
        else if (x < 0) r = y;
        else if (y < 0) r = x;
        else r = min(x, y);
        cout << r << '\n';
    }

    return 0;
}
0