結果

問題 No.967 引き算をして門松列(その2)
ユーザー hipopohipopo
提出日時 2020-04-11 14:36:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 2,040 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 137,124 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 05:14:02
合計ジャッジ時間 2,286 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 11 ms
4,348 KB
testcase_04 AC 11 ms
4,348 KB
testcase_05 AC 12 ms
4,348 KB
testcase_06 AC 11 ms
4,348 KB
testcase_07 AC 15 ms
4,348 KB
testcase_08 AC 26 ms
4,348 KB
testcase_09 AC 32 ms
4,348 KB
testcase_10 AC 34 ms
4,348 KB
testcase_11 AC 33 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    int t;
    cin >> t;
    const ll INF = 1e18;
    rep(_t, t) {
        ll h[3], c[3];
        rep(i, 3) cin >> h[i];
        rep(i, 3) cin >> c[i];
        auto cost = [&](int r1, int r2, int r3){
            ll nh1 = h[r1];
            ll nh2 = min(h[r2], nh1 - 1);
            ll nh3 = min(h[r3], nh2 - 1);
            if (nh3 <= 0) return INF;
            return (h[r2] - nh2) * c[r2] + (h[r3] - nh3) * c[r3];
        };
        ll min_cost = min({cost(0, 2, 1), cost(1, 0, 2), cost(1, 2, 0), cost(2, 0, 1)});
        if (min_cost != INF) cout << min_cost << endl;
        else cout << -1 << endl;
    }
}
0