結果

問題 No.968 引き算をして門松列(その3)
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2019-12-29 13:39:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,036 bytes
コンパイル時間 800 ms
コンパイル使用メモリ 97,908 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 18:43:02
合計ジャッジ時間 1,808 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
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 <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] = {y,z,x};
  ll d3[3] = {a,b,c};
  ll dd[3][3] = {
    {0,-1,-1},
    {-1,0,-1},
    {-1,-1,0}
  };
  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 e3[3] = {d1[d[0]],d1[d[1]],d1[d[2]]};
    ll cost = 0;
    rep(i,0,2){
      ll q = max(0LL,((e1[i]+1)-e1[i+1]));
      cost += q*e2[i+1];
      cout << cost << endl;
      e1[i+1]+=q;
      e3[0]+=dd[i+1][0]*q;
      e3[1]+=dd[i+1][1]*q;
      e3[2]+=dd[i+1][2]*q;
    }
    if(e3[0]>0&&e3[1]>0&&e3[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