結果

問題 No.967 引き算をして門松列(その2)
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2019-11-09 12:56:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,776 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 97,008 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 18:41:23
合計ジャッジ時間 1,978 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define endl "\n"
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll isK(ll a, ll b, ll c){
  vector<pair<ll,ll> > v;
  v.pb(mp(a,0));
  v.pb(mp(b,1));
  v.pb(mp(c,2));
  sort(all(v));
  if(v[0].fi!=v[1].fi&&v[1].fi!=v[2].fi){
    if(v[0].se==1||v[2].se==1){
      return 1;
    }
  }
  return 0;
}

ll f(ll a, ll b, ll c, ll x, ll y, ll z){
  ll mn = 2000000000000000010LL;
  ll d[3];
  ll d1[3] = {a,b,c};
  ll d2[3] = {x,y,z};
  vector<ll> v;
  rep(i,0,3)v.pb(i);
  do{
    if(isK(v[0],v[1],v[2])==0)continue;
    rep(i,0,3){
      d[i] = v[i];
    }
    ll e1[3] = {d1[d[0]],d1[d[1]],d1[d[2]]};
    ll e2[3] = {d2[d[0]],d2[d[1]],d2[d[2]]};
    ll cost = 0;
    rep(i,0,2){
      ll q = max(0LL,(e1[i+1]-(e1[i]-1)));
      cost += q*e2[i+1];
      e1[i+1]-=q;
    }
    if(e1[2]>0){
      mn = min(mn,cost);
    }
  }while(next_permutation(all(v)));
  if(mn==2000000000000000010LL){
    return -1;
  }
  return mn;
}

int main(){
  ll T;
  cin>>T;
  rep(t,0,T){
    ll a,b,c,x,y,z;
    cin>>a>>b>>c>>x>>y>>z;
    cout << f(a,b,c,x,y,z) << endl;
  }
  return 0;
}
0