結果

問題 No.968 引き算をして門松列(その3)
ユーザー parukiparuki
提出日時 2020-01-28 16:53:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,095 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 169,708 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 17:52:48
合計ジャッジ時間 2,391 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

bool isKado(ll x, ll y, ll z) {
    if (x == y || y == z || z == x)return false;
    if (x <= 0 || y <= 0 || z <= 0)return false;
    static ll a[3];
    a[0] = x; a[1] = y; a[2] = z;
    sort(a, a + 3);
    return y != a[1];
}

void solve() {
    int T;
    cin >> T;
    vi P{ 0,1,2 };
    while (T--) {
        ll A[3], X[3], U[3];
        rep(i, 3) {
            cin >> A[i];
        }
        cin >> X[2] >> X[0] >> X[1];
        ll ans = LLONG_MAX;
        do {
            rep(i, 3) {
                U[i] = A[i];
            }
            ll cost = 0;
            // 二番目に高い=>一番高い
            for (int i = 1; i >= 0; --i) {
                ll maxi = LLONG_MIN;
                int p = P[i];
                FOR(j, i + 1, 3) {
                    int q = P[j];
                    smax(maxi, U[q]);
                }
                if (U[p] <= maxi) {
                    ll cuts = maxi - U[p] + 1;
                    rep(j, 3) {
                        if (j != i) {
                            int q = P[j];
                            U[q] -= cuts;
                        }
                    }
                    cost += cuts * X[p];
                }
            }
            if (isKado(U[0], U[1], U[2])) {
                smin(ans, cost);
            }
        } while (next_permutation(all(P)));

        cout << (ans == LLONG_MAX ? -1 : ans) << endl;
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0