結果

問題 No.967 引き算をして門松列(その2)
ユーザー MisterMister
提出日時 2020-04-23 22:22:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,351 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 69,476 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-04 04:18:16
合計ジャッジ時間 1,615 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>

using lint = long long;
constexpr lint INF = 1LL << 50;

void solve() {
    lint a, b, c, ca, cb, cc;
    std::cin >> a >> b >> c >> ca >> cb >> cc;

    lint ans = INF;
    {
        // b is max
        lint na = a, nb = b, nc = c;
        lint cost = 0;

        if (na >= nb) {
            cost += (na - nb + 1) * ca;
            na = nb - 1;
        }
        if (nc >= nb) {
            cost += (nc - nb + 1) * cc;
            nc = nb - 1;
        }

        if (na == nc) {
            cost += std::min(ca, cc);
            --na;
        }

        if (na > 0 && nb > 0 && nc > 0) {
            ans = std::min(ans, cost);
        }
    }

    {
        // b is min
        lint na = a, nb = b, nc = c;
        lint cost = 0;

        if (na == nc) {
            cost += std::min(ca, cc);
            --na;
        }

        if (na <= nb) {
            cost += (nb - na + 1) * cb;
            nb = na - 1;
        }

        if (nc <= nb) {
            cost += (nb - nc + 1) * cb;
            nb = nc - 1;
        }

        if (na > 0 && nb > 0 && nc > 0) {
            ans = std::min(ans, cost);
        }
    }

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

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int q;
    std::cin >> q;
    while (q--) solve();

    return 0;
}
0