結果

問題 No.967 引き算をして門松列(その2)
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2019-12-29 23:00:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,734 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 12:05:46
合計ジャッジ時間 1,684 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 10 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 11 ms
5,376 KB
testcase_06 AC 11 ms
5,376 KB
testcase_07 AC 13 ms
5,376 KB
testcase_08 AC 23 ms
5,376 KB
testcase_09 AC 28 ms
5,376 KB
testcase_10 AC 29 ms
5,376 KB
testcase_11 AC 30 ms
5,376 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 f(ll a, ll b, ll c, ll x, ll y, ll z){
  ll ret = 0;
  ll d1 = max(0LL,b-(a-1));
  ret += y*d1;
  b -= d1;
  ll d2 = max(0LL,c-(b-1));
  ret += z*d2;
  c -= d2;
  if(c>0){
    return ret;
  }
  else{
    return 2000000000000000010LL;
  }
}

int main(){
  int T;
  cin>>T;
  for(int t = 0; t < T; t++){
    ll d[3];
    ll e[3];
    cin>>d[0]>>d[1]>>d[2]>>e[0]>>e[1]>>e[2];
    rep(i,0,3){
      if(d[i]<1||1000000000<d[i]){
        cout << -2 << endl;
        continue;
      }
      if(e[i]<1||1000000000<e[i]){
        cout << -2 << endl;
        continue;
      }      
    }
    ll ans = 2000000000000000010LL;
    ans = min(ans,f(d[1],d[0],d[2],e[1],e[0],e[2]));
    ans = min(ans,f(d[1],d[2],d[0],e[1],e[2],e[0]));
    ans = min(ans,f(d[0],d[2],d[1],e[0],e[2],e[1]));
    ans = min(ans,f(d[2],d[0],d[1],e[2],e[0],e[1]));
    if(ans==2000000000000000010LL){
      cout << -1 << endl;
    }
    else{
      cout << ans << endl;
    }
  }
  return 0;
}
0