結果

問題 No.966 引き算をして門松列(その1)
ユーザー CleyLCleyL
提出日時 2022-02-21 10:37:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 2,091 bytes
コンパイル時間 556 ms
コンパイル使用メモリ 67,648 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 01:35:18
合計ジャッジ時間 1,616 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;
void solve(){
    int a,b,c;cin>>a>>b>>c;
    if(a==b && b==c){
        if(a >= 3)cout << 3 << endl;
        else cout << -1 << endl;
    }else if(a==c){
        if(a>b){
            if(a-1 == b){
                if(b==1){
                    cout << -1 << endl;
                }else{
                    cout << 2 << endl;
                }
            }else{
                cout << 1 << endl;
            }
        }else{
            if(a==1){
                cout << -1 << endl;
            }else{
                cout << 1 << endl;
            }
        }
    }else if(a==b){
        if(a>c){
            if(a-1==c){
                if(c==1){
                    cout << -1 << endl;
                }else{
                    cout << 2 << endl;
                }
            }else{
                cout << 1 << endl;
            }
        }else{
            if(a==1){
                cout << -1 << endl;
            }else{
                cout << 1 << endl;
            }
        }
    }else if(b==c){
        if(a<c){
            if(a==c-1){
                if(a==1){
                    cout << -1 << endl;
                }else{
                    cout << 2 << endl;
                }
            }else{
                cout << 1 << endl;
            }
        }else{
            if(c==1){
                cout << -1 << endl;
            }else{
                cout << 1 << endl;
            }
        }
    }else{
        if((a>b && b<c) || (a<b&&b>c)){
            cout << 0 << endl;
        }else{
            if(a>b)swap(a,c);
            int ans = -1;
            if(b-a == 1){
                if(a!=1){
                    ans = c-a+1;
                }
            }else{
                ans = c-b+1;
            }
            if(a!=1){
                if(ans!=-1){
                    ans = min(ans,b-a+1);
                }else{
                    ans = b-a+1;
                }
            }
            cout << ans << endl;
        }
    }
}
int main(){
    int n;cin>>n;
    for(int i = 0; n > i; i++){
        solve();
    }
}
0