結果

問題 No.966 引き算をして門松列(その1)
ユーザー chocoruskchocorusk
提出日時 2020-01-13 20:41:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,155 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 107,724 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:12:32
合計ジャッジ時間 1,584 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int t;
	cin>>t;
	const ll INF=1e9+7;
	for(int z=0; z<t; z++){
		ll a, b, c;
		cin>>a>>b>>c;
		if(a>c) swap(a, c);
		ll p=INF, q=INF;
		if(a<b){
			if(b<=c){
				if(a!=b-1) p=c-b+1;
				else if(a>=2) p=c-b+2;
			}else{
				if(a!=c) p=0;
				else if(a>=2) p=1;
			}
		}else if(a==b){
			if(a>=3) p=c-a+3;
		}
		if(a<b){
			if(a>=2) q=b-a+1;
		}else if(a>b){
			if(a!=c) q=0;
			else{
				if(a-b>=2) q=1;
				else if(b>=2) q=2;
			}
		}else{
			if(b!=c){
				if(a>=2) q=1;
			}else{
				if(b>=3) q=3;
			}
		}
		ll ans=min(p, q);
		if(ans==INF) cout<<-1<<endl;
		else cout<<ans<<endl;
		
	}
	return 0;
}
0