結果

問題 No.966 引き算をして門松列(その1)
ユーザー Y17Y17
提出日時 2020-01-13 21:42:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 3,118 ms
コンパイル使用メモリ 144,512 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 15:51:27
合計ジャッジ時間 1,989 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long

int solve(int a, int b, int c){

    int ans = 0;

    if(a <= b){
        if(a == 1) return LLONG_MAX;
        ans += b-(a-1);
        b = a-1;
    }

    if(b <= c){
        if(b == 1) return LLONG_MAX;
        ans += c-(b-1);
    }

    return ans;
}

signed main(){
    int t;
    cin >> t;

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

        int ans = min({solve(b, a, c), solve(b, c, a), solve(a, c, b), solve(c, a, b)});

        if(ans == LLONG_MAX){
            cout << -1 << endl;
        }else{
            cout << ans << endl;
        }
    }

    return 0;
}
0