結果

問題 No.967 引き算をして門松列(その2)
ユーザー sten_sansten_san
提出日時 2021-04-20 23:48:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,351 bytes
コンパイル時間 1,931 ms
コンパイル使用メモリ 203,828 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 08:59:35
合計ジャッジ時間 3,301 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr); cout.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

int main() {
    constexpr int64_t inf = INT64_MAX / 4;

    auto kadomatsu = [](int a, int b, int c) {
        array<tuple<int, int, int>, 4> ans;
        fill(begin(ans), end(ans), make_tuple(a, b, c));

        {
            auto &[a, b, c] = ans[0];
            if (b <= a) {
                a = b - 1;
            }
            if (a <= c) {
                c = a - 1;
            }
        }

        {
            auto &[a, b, c] = ans[1];
            if (b <= c) {
                c = b - 1;
            }
            if (c <= a) {
                a = c - 1;
            }
        }

        {
            auto &[a, b, c] = ans[2];
            if (c <= a) {
                a = c - 1;
            }
            if (a <= b) {
                b = a - 1;
            }
        }

        {
            auto &[a, b, c] = ans[3];
            if (a <= c) {
                c = a - 1;
            }
            if (c <= b) {
                b = c - 1;
            }
        }

        return ans;
    };

    int t; cin >> t;
    while (t--) {
        int a, b, c; cin >> a >> b >> c;
        int64_t x, y, z; cin >> x >> y >> z;

        int64_t ans = inf;
        for (auto [d, e, f] : kadomatsu(a, b, c)) {
            if (d <= 0 || e <= 0 || f <= 0) {
                continue;
            }

            ans = min(ans, x * abs(a - d) + y * (b - e) + z * (c - f));
        }

        if (ans != inf) {
            cout << ans << endl;
        }
        else {
            cout << -1 << endl;
        }
    }
}

0