結果

問題 No.967 引き算をして門松列(その2)
ユーザー furafura
提出日時 2020-05-29 00:04:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 2,158 ms
コンパイル使用メモリ 193,300 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 15:57:14
合計ジャッジ時間 3,343 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 12 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 12 ms
5,376 KB
testcase_06 AC 12 ms
5,376 KB
testcase_07 AC 15 ms
5,376 KB
testcase_08 AC 27 ms
5,376 KB
testcase_09 AC 33 ms
5,376 KB
testcase_10 AC 35 ms
5,376 KB
testcase_11 AC 34 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

void solve(){
	lint a,b,c,x,y,z; cin>>a>>b>>c>>x>>y>>z;

	lint ans=LLONG_MAX;
	// b が最大
	if(b>=3 && !(a==1 && c==1)){
		lint ta=a,tc=c;

		lint res=0;
		if(a>=b) res+=x*(a-b+1), a=b-1;
		if(c>=b) res+=z*(c-b+1), c=b-1;
		if(a==c) res+=min(x,z);
		ans=min(ans,res);

		a=ta; c=tc;
	}
	// b が最小
	if(a>=2 && c>=2 && !(a==2 && c==2)){
		lint res=0;
		if(a==c){
			res+=min(x,z);
			a--;
		}
		if(b>=min(a,c)) res+=y*(b-min(a,c)+1);
		ans=min(ans,res);
	}
	printf("%lld\n",ans<LLONG_MAX?ans:-1);
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0