結果

問題 No.968 引き算をして門松列(その3)
ユーザー beetbeet
提出日時 2020-01-13 20:48:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 1,975 ms
コンパイル使用メモリ 199,472 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:24:28
合計ジャッジ時間 3,039 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 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<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int INF = 1e18;
Int p1_1(Int a,Int b,Int c,Int x,Int y,Int z){
  // a < b > c, a < c < b
  int res=0;
  while(a>=c) a--,b--,res+=x;
  while(c>=b) a--,c--,res+=z;
  if(min({a,b,c})<=0) return INF;
  return res;
}

Int p1(Int a,Int b,Int c,Int x,Int y,Int z){
  // a < b > c
  return min(p1_1(a,b,c,x,y,z),p1_1(c,b,a,z,y,x));
}

Int p2_1(Int a,Int b,Int c,Int x,Int y,Int z){
  // a > b < c, b < a < c
  int res=0;
  while(b>=a) b--,c--,res+=y;
  while(a>=c) a--,b--,res+=x;
  if(min({a,b,c})<=0) return INF;
  return res;
}

Int p2(Int a,Int b,Int c,Int x,Int y,Int z){
  // a > b < c
  return min(p2_1(a,b,c,x,y,z),p2_1(c,b,a,z,y,x));
}

signed solve(){
  Int a,b,c,x,y,z;
  cin>>a>>b>>c>>x>>y>>z;
  Int ans=min(p1(a,b,c,x,y,z),p2(a,b,c,x,y,z));
  if(ans==INF) ans=-1;
  cout<<ans<<endl;
  return 0;
}

signed main(){
  Int T;
  cin>>T;
  while(T--) solve();
  return 0;
}
0