結果

問題 No.966 引き算をして門松列(その1)
ユーザー chocopuuchocopuu
提出日時 2020-01-13 22:43:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,058 bytes
コンパイル時間 3,761 ms
コンパイル使用メモリ 188,440 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 18:23:54
合計ジャッジ時間 3,409 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<endl;}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;



signed main(){
	int Q;
	in(Q);
	vector<int>ans;
	while(Q--){
		int ret = INF;
		auto a = mv(3);
		in(a);
		int flg;
		auto f = [&](int i,int j,int k){
			int ret = 0;
			int top = a[i];
			int middle = min(a[i]-1,a[j]);
			int bottom = min(middle-1,a[k]);
			if(bottom <= 0)flg = 0;
			return abs(a[j]-middle)+abs(a[k]-bottom);
		};
		REP(i,3){
			REP(j,3){
				REP(k,3){
					if(i == j)continue;
					if(j == k)continue;
					if(k == i)continue;
					if(j == 1)continue;
					flg = 1;
					int t = f(i,j,k);
					if(flg)CHMIN(ret,t);
				}
			}
		}
		ans.push_back(ret);
	}
	for(auto e:ans){
		if(e == INF)out(-1);
		else out(e);
	}
}
0