結果

問題 No.968 引き算をして門松列(その3)
ユーザー chocoruskchocorusk
提出日時 2020-01-13 21:57:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,188 bytes
コンパイル時間 1,207 ms
コンパイル使用メモリ 113,776 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-24 16:28:27
合計ジャッジ時間 2,125 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
bool check(ll a, ll b, ll c){
	if(a<=0 || b<=0 || c<=0) return false;
	if((a<b && b>c && a!=c) || (a>b && b<c && a!=c)) return true;
	else return false;
}
int main()
{
	int t;
	cin>>t;
	const ll INF=3e18;
	for(int i=0; i<t; i++){
		ll a, b, c, x, y, z;
		cin>>a>>b>>c>>x>>y>>z;
		if(a>c) swap(a, c), swap(x, z);
		if(check(a, b, c)){
			cout<<0<<endl;
			continue;
		}
		ll ans=INF;
		vector<ll> v;
		for(int k=0; k<4; k++){
			if(a-k>0) v.push_back(a-k);
			if(b-k>0) v.push_back(b-k);
			if(c-k>0) v.push_back(c-k);
		}
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				ll a1=a-i, b1=b-i-j, c1=c-j;
				if(a1<=0 || b1<=0 || c1<=0 || a1==c1) continue;
				if(check(a1, b1, c1)){
					ans=min(ans, x*i+y*j);
					continue;
				}
				if(b1>=2){
					if(a1>c1 && c1-(a1-b1+1)>0) ans=min(ans, x*i+y*j+z*(a1-b1+1));
					else if(a1<c1 && a1-(c1-b1+1)>0)  ans=min(ans, x*i+y*j+z*(c1-b1+1));
				}
			}
		}
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				ll a1=a-j, b1=b-i, c1=c-i-j;
				if(a1<=0 || b1<=0 || c1<=0 || a1==b1) continue;
				if(check(a1, b1, c1)){
					ans=min(ans, y*i+z*j);
					continue;
				}
				if(a1>b1 && b1>=c1 && check(a1-(b1-c1+1), b1-(b1-c1+1), c1)){
					ans=min(ans, y*i+z*j+x*(b1-c1+1));
				}
			}
		}
		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				ll a1=a-i-j, b1=b-j, c1=c-i;
				if(a1<=0 || b1<=0 || c1<=0 || b1==c1) continue;
				if(check(a1, b1, c1)){
					ans=min(ans, z*i+x*j);
					continue;
				}
				if(a1<=b1 && b1<c1 && check(a1, b1-(b1-a1+1), c1-(b1-a1+1))){
					ans=min(ans, z*i+x*j+y*(b1-a1+1));
				}
			}
		}
		if(ans==INF) cout<<-1<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}
0