結果

問題 No.967 引き算をして門松列(その2)
ユーザー leaf_1415leaf_1415
提出日時 2020-01-13 22:36:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,490 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 60,492 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 18:14:03
合計ジャッジ時間 1,600 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
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 <iostream>
#include <string>
#include <algorithm>
#define llint long long
#define inf 3e18

using namespace std;

llint T;
llint a, b, c, x, y, z;

llint calc(llint a, llint b, llint c, llint x, llint y, llint z)
{
	//cout<< a << " " << b << " " << c << " " << x << " " << y << " " << z << endl;
	if(a == b && b == c){
		if(a <= 2) return inf;
		llint ans = 2*y+min(x, z);
		ans = min(ans, x+z+min(x, z));
		return ans;
	}
	
	if(a == b){
		llint ans = inf;
		if(a > 1) ans = min(ans, calc(a-1, b, c, x, y, z)+x);
		if(b > 1) ans = min(ans, calc(a, b-1, c, x, y, z)+y);
		return ans;
	}
	if(b == c){
		llint ans = inf;
		if(b > 1) ans = min(ans, calc(a, b-1, c, x, y, z)+y);
		if(c > 1) ans = min(ans, calc(a, b, c-1, x, y, z)+z);
		return ans;
	}
	if(a == c){
		llint ans = inf;
		if(a > 1) ans = min(ans, calc(a-1, b, c, x, y, z)+x);
		if(c > 1) ans = min(ans, calc(a, b, c-1, x, y, z)+z);
		return ans;
	}
	
	if(a > b){
		if(b < c) return 0;
		return calc(c, b, a, z, y, x);
	}
	if(b > c) return 0;
	
	llint ans = inf;
	ans = (c-b)*z;
	llint p = min(y, z);
	ans += p;
	if(a == b-1){
		if(a == 1) ans = inf;
		else ans += p;
	}
	if(a > 1) ans = min(ans, (b-a+1)*y);
	//cout<< a << " " << b << " " << c << " " << ans << endl;
	return ans;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> T;
	for(int t = 0; t < T; t++){
		cin >> a >> b >> c >> x >> y >> z;
		llint ans = calc(a, b, c, x, y, z);
		if(ans > inf/2) ans = -1;
		cout << ans << endl;
	}
	return 0;
}
0