結果

問題 No.967 引き算をして門松列(その2)
ユーザー finefine
提出日時 2020-01-13 21:39:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,308 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 174,036 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 15:45:09
合計ジャッジ時間 4,232 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 118 ms
4,380 KB
testcase_04 AC 164 ms
4,384 KB
testcase_05 AC 165 ms
4,384 KB
testcase_06 AC 164 ms
4,384 KB
testcase_07 AC 165 ms
4,384 KB
testcase_08 AC 260 ms
4,380 KB
testcase_09 AC 282 ms
4,380 KB
testcase_10 AC 279 ms
4,384 KB
testcase_11 AC 288 ms
4,384 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;
    for (int i = 0; i < 3; ++i) {
        if (c[i] < 1) return INF;
        if (a[i] < c[i]) return INF;
        res += b[i] * (a[i] - c[i]);
    }

    vector<ll> d = c;
    sort(d.begin(), d.end());
    if (d[0] == d[1] || d[1] == d[2]) return INF;
    if (c[1] == d[0] || c[1] == d[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 = 0; i < 3; ++i) {
            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