結果

問題 No.966 引き算をして門松列(その1)
ユーザー 沙耶花沙耶花
提出日時 2020-01-13 20:37:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 979 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 198,152 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:07:47
合計ジャッジ時間 2,668 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000009



int main(){
	
	int T;
	cin>>T;
	
	for(int i=0;i<T;i++){
		int A,B,C;
		cin>>A>>B>>C;
		if(A>B&&C>B){
			if(A==C){
				if(B+1==A){
					if(B==1)cout<<-1<<endl;
					else cout<<2<<endl;
				}
				else{
					cout<<1<<endl;
				}
				
			}
			else{
				cout<<0<<endl;
			}
			continue;
		}
		if(A<B&&C<B){
			if(A==C){
				if(A==1)cout<<-1<<endl;
				else cout<<1<<endl;
			}
			else{
				cout<<0<<endl;
			}
			continue;
		}
		if(A>C)swap(A,C);
		
		int ans = 0;
		int x = 0;
		if(A==B){
			ans++;
			x++;
			if(A==C){
				ans+=2;
				x++;
			}
			if(B-x<=0)ans = -1;
		}
		else if(B==C){
			ans++;
			x++;
			if(C-1==A){
				ans++;
				x++;
			}
			if(C-x<=0)ans = -1;
		}
		else{
			ans = Inf;
			if(A!=1)ans = min(ans,B-A+1);
			if(B-A!=1)ans = min(ans,C-B+1);
			if(ans==Inf)ans = -1;
		}
		cout<<ans<<endl;
	}

	return 0;
}
0