結果

問題 No.158 奇妙なお使い
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-27 22:25:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 406 ms / 5,000 ms
コード長 1,859 bytes
コンパイル時間 2,627 ms
コンパイル使用メモリ 177,468 KB
実行使用メモリ 32,952 KB
最終ジャッジ日時 2023-09-12 06:27:47
合計ジャッジ時間 4,140 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 406 ms
32,952 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 49 ms
7,644 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 8 ms
4,460 KB
testcase_22 AC 9 ms
5,464 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    vector<int> A, B, C;
    int Db, Dc;
    void input() {
        A.resize(3);
        B.resize(3);
        C.resize(3);
        cin >> A >> Db >> B >> Dc >> C;
    }

    vector<int> try_(int d, int x, int y, int z) {
        vector<int> ret;
        int t = d;
        int p = min(x, t / 1000);
        t -= p * 1000;
        int q = min(y, t / 100);
        t -= q * 100;
        int r = min(z, t / 1);
        if (p * 1000 + q * 100 + r * 1 < d) return ret;
        ret.push_back(p);
        ret.push_back(q);
        ret.push_back(r);
        return ret;
    }

    map< tuple<int, int, int>, int > cache;
    int f(int x, int y, int z) {
        //cerr << "f " << x << " " << y << " " << z << endl;
        auto key = make_tuple(x, y, z);
        if (cache.count(key)) return cache[key];
        vector<int> b = try_(Db, x, y, z);
        vector<int> c = try_(Dc, x, y, z);
        int ans = 0;
        if (not b.empty()) {
            ans = max(ans, 1 + f(x - b[0] + B[0], y - b[1] + B[1], z - b[2] + B[2]));
        }
        if (not c.empty()) {
            ans = max(ans, 1 + f(x - c[0] + C[0], y - c[1] + C[1], z - c[2] + C[2]));
        }
        return cache[key] = ans;
    }

    void solve() {
        cout << f(A[0], A[1], A[2]) << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0