結果

問題 No.158 奇妙なお使い
ユーザー kimiyukikimiyuki
提出日時 2016-09-27 22:35:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,846 bytes
コンパイル時間 1,189 ms
コンパイル使用メモリ 96,536 KB
実行使用メモリ 43,292 KB
最終ジャッジ日時 2024-05-01 05:50:32
合計ジャッジ時間 7,686 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 39 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("-O3")
#include <iostream>
#include <map>
#include <queue>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
const int inf = 1e9+7;
const int N0 = 1000;
const int N1 = 100;
const int N2 = 1;
struct wallet_t { int n0, n1, n2; };
int sum(wallet_t const & a) { return N0*a.n0 + N1*a.n1 + N2*a.n2; }
bool valid(wallet_t const & a) { return a.n0 >= 0 and a.n1 >= 0 and a.n2 >= 0; }
wallet_t operator + (wallet_t const & a, wallet_t const & b) { return (wallet_t) { a.n0 + b.n0, a.n1 + b.n1, a.n2 + b.n2 }; }
wallet_t operator - (wallet_t const & a, wallet_t const & b) { return (wallet_t) { a.n0 - b.n0, a.n1 - b.n1, a.n2 - b.n2 }; }
bool operator < (wallet_t const & a, wallet_t const & b) { return make_tuple(sum(a), a.n0, a.n1, a.n2) < make_tuple(sum(b), b.n0, b.n1, b.n2); }
istream & operator >> (istream & in, wallet_t & a) { return in >> a.n0 >> a.n1 >> a.n2; }
int main() {
    wallet_t wa, wb, wc; int db, dc; cin >> wa >> db >> wb >> dc >> wc;
    int ans = - inf;
    map<wallet_t,int> dp;
    priority_queue<wallet_t> que;
    que.push(wa);
    while (not que.empty()) {
        wallet_t w = que.top(); que.pop();
        setmax(ans, dp[w]);
        repeat (i0,w.n0+1) {
            repeat (i1,w.n1+1) {
                auto foo = [&](int d, wallet_t wd) {
                    int i2 = (d - N0*i0 - N1*i1) / N2;
                    if (0 <= i2 and i2 <= w.n2) {
                        wallet_t nw = (w - ((wallet_t) { i0, i1, i2 })) + wd;
                        if (not dp.count(nw)) que.push(nw);
                        setmax(dp[nw], dp[w]+1);
                    }
                };
                foo(db, wb);
                foo(dc, wc);
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0