結果

問題 No.966 引き算をして門松列(その1)
ユーザー furafura
提出日時 2020-05-06 03:52:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 2,487 ms
コンパイル使用メモリ 197,616 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 23:17:02
合計ジャッジ時間 2,823 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

int main(){
	int q; scanf("%d",&q);
	rep(_,q){
		lint a,b,c; scanf("%lld%lld%lld",&a,&b,&c);

		lint ans=INF;
		if(b>=3){ // b を最大値にする
			lint a2=a,c2=c,cost=0;
			if(a>=b) a2=b-1, cost+=a-b+1;
			if(c>=b) c2=b-1, cost+=c-b+1;
			if(a2==c2) a2--, cost++;
			if(a2==0) cost=INF;
			ans=min(ans,cost);
		}
		if(a>=2 && c>=2){ // b を最小値にする
			lint a2=a,c2=c,cost=0;
			if(a==c){
				a2--; cost++;
			}
			cost+=max({b-a2+1,b-c2+1,0LL});
			if(a2==1) cost=INF;
			ans=min(ans,cost);
		}
		printf("%lld\n",ans<INF?ans:-1);
	}

	return 0;
}
0