結果

問題 No.967 引き算をして門松列(その2)
ユーザー tubuanntubuann
提出日時 2020-01-13 20:50:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,377 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 199,592 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 13:29:14
合計ジャッジ時間 2,853 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

const ll MX=2e18;

ll solve1(ll A,ll B,ll C,ll X,ll Y,ll Z){
  ll ret=MX;
  ll bd=B;
  ll cd=min(C,B-1);
  ll ad=min(A,cd-1);
  if(ad>0 && bd>0 && cd>0){ret=min(ret,(A-ad)*X+(B-bd)*Y+(C-cd)*Z);}
  cd=C;
  ad=min(A,cd-1);
  bd=min(B,ad-1);
  if(ad>0 && bd>0 && cd>0){ret=min(ret,(A-ad)*X+(B-bd)*Y+(C-cd)*Z);}
  
  return ret;
}

ll solve2(ll A,ll B,ll C,ll X,ll Y,ll Z){
  ll ret=min(solve1(A,B,C,X,Y,Z),solve1(C,B,A,Z,Y,X));
  return ret==MX?-1LL:ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll T;
  cin>>T;
  for(int i=0;i<T;i++){
    ll a,b,c,x,y,z;
    cin>>a>>b>>c>>x>>y>>z;
    cout<<solve2(a,b,c,x,y,z)<<endl;
  }

  return 0;
}
0