結果

問題 No.966 引き算をして門松列(その1)
ユーザー kikagekikage
提出日時 2020-04-12 20:50:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 56,672 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 07:20:40
合計ジャッジ時間 1,154 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;
int main(){
    int T;
    cin >> T;
    for(int i=0,A,B,C;i<T;i++){
        cin >> A >> B >> C;

        int cnt1=-1,cnt2=-1;
        bool flag1=true,flag2=true;
        
        if(B>=3 && (A>1 || C>1)){
            int a=A,b=B,c=C;
            cnt1=0;
            if(a>=b){
                cnt1+=a-(b-1);
                a=b-1;
            }
            if(c>=b){
                cnt1+=c-(b-1);
                c=b-1;
            }
            if(a==c){cnt1++;a--;}
        }else flag1=false;
        
        if((A>2 && C>1) || (A>1 && C>2)){
            cnt2=0;
            int a=A,b=B,c=C;
            if(a==c){a--;cnt2++;}
            if(b>=min(a,c))cnt2+=b-(min(a,c)-1);
        }else flag2=false;
        if( flag1 &&  flag2)cout << min(cnt1,cnt2) << endl;
        if( flag1 && !flag2)cout << cnt1 << endl;
        if(!flag1 &&  flag2)cout << cnt2 << endl;
        if(!flag1 && !flag2)cout << -1 << endl;
    }
    return 0;
}
0