結果

問題 No.968 引き算をして門松列(その3)
ユーザー finefine
提出日時 2020-01-13 21:47:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 454 ms / 2,000 ms
コード長 1,491 bytes
コンパイル時間 1,626 ms
コンパイル使用メモリ 173,456 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 16:06:36
合計ジャッジ時間 5,355 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll INF = 1e18;

ll calc(vector<ll>& a, vector<ll>& b, vector<ll>& c) {
    ll res = 0;
    vector<ll> d = a;
    for (int i = 0; i < 3; ++i) {
        ll cnt = c[i] - a[i];
        if (cnt < 0) return INF;
        for (int j = 0; j < 3; ++j) {
            if (i == j) continue;
            d[j] -= cnt;
        }
        res += b[i] * cnt;
    }

    for (int i = 0; i < 3; ++i) {
        if (d[i] <= 0) return INF;
    }

    vector<ll> e = d;
    sort(e.begin(), e.end());
    if (e[0] == e[1] || e[1] == e[2]) return INF;
    if (d[1] == e[0] || d[1] == e[2]) return res;
    else return INF;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int lo = 0; lo < t; ++lo) {
        vector<ll> a(3);
        vector<ll> b(3);
        for (int i = 0; i < 3; ++i) {
            cin >> a[i];
        }
        for (int i : {2, 0, 1}) {
            cin >> b[i];
        }

        vector<ll> v;
        for (int i = 0; i < 3; ++i) {
            v.push_back(a[i]);
            v.push_back(a[i] + 1);
            v.push_back(a[i] + 2);
        }

        ll ans = INF;
        for (ll i : v) {
            for (ll j : v) {
                for (ll k : v) {
                    vector<ll> c = {i, j, k};
                    ans = min(ans, calc(a, b, c));
                }
            }
        }
        cout << (ans >= INF ? -1 : ans) << "\n";
    }

    return 0;
}
0