結果

問題 No.158 奇妙なお使い
ユーザー codershifthcodershifth
提出日時 2015-12-28 01:45:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 1,686 bytes
コンパイル時間 1,152 ms
コンパイル使用メモリ 147,216 KB
実行使用メモリ 91,224 KB
最終ジャッジ日時 2023-09-11 22:57:47
合計ジャッジ時間 3,236 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
90,268 KB
testcase_01 AC 27 ms
90,224 KB
testcase_02 AC 27 ms
90,188 KB
testcase_03 AC 27 ms
90,196 KB
testcase_04 AC 47 ms
91,036 KB
testcase_05 AC 27 ms
90,188 KB
testcase_06 AC 27 ms
90,104 KB
testcase_07 AC 27 ms
90,088 KB
testcase_08 AC 27 ms
90,160 KB
testcase_09 AC 28 ms
90,184 KB
testcase_10 AC 27 ms
90,300 KB
testcase_11 AC 28 ms
90,280 KB
testcase_12 AC 27 ms
90,164 KB
testcase_13 AC 27 ms
90,164 KB
testcase_14 AC 27 ms
90,084 KB
testcase_15 AC 27 ms
90,124 KB
testcase_16 AC 27 ms
90,204 KB
testcase_17 AC 28 ms
90,268 KB
testcase_18 AC 28 ms
90,232 KB
testcase_19 AC 27 ms
90,260 KB
testcase_20 AC 27 ms
90,260 KB
testcase_21 AC 28 ms
90,600 KB
testcase_22 AC 28 ms
91,224 KB
testcase_23 AC 27 ms
90,092 KB
testcase_24 AC 27 ms
90,192 KB
testcase_25 AC 27 ms
90,084 KB
testcase_26 AC 27 ms
90,264 KB
testcase_27 AC 27 ms
90,248 KB
testcase_28 AC 27 ms
90,288 KB
testcase_29 AC 27 ms
90,196 KB
testcase_30 AC 27 ms
90,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;

array<int,3> A,B,C;
int Db,Dc;
ll dp[11][101][10001];
// Db,Dc <= 10000 かつ支払い金額よりも多い受け取り金額がないことから、
// A1000,A100,A1 の最大所持数は10,100,10000となる

class StrangeErrand {
public:
    ll calc(int a, int b, int c) {
        if (dp[a][b][c] >= 0)
            return dp[a][b][c];
        ll maxCnt = 0;
        // できるだけ 小さい貨幣が残るようにしてやる
        REP(i,2)
        {
            int aa = a;
            int bb = b;
            int cc = c;
            int dd = i==0? Db : Dc;
            array<int,3> D = i==0? B : C;

            while(aa && dd >= 1000)
            {
                --aa;
                dd -= 1000;
            }
            while(bb && dd >= 100)
            {
                --bb;
                dd -= 100;
            }
            if (dd <= cc)
                maxCnt = max(maxCnt, calc(aa+D[0], bb+D[1], cc-dd+D[2])+1);
        }
        return dp[a][b][c] = maxCnt;
    }
    void solve(void) {
        REP(i,3) cin>>A[i];
        cin>>Db;
        REP(i,3) cin>>B[i];
        cin>>Dc;
        REP(i,3) cin>>C[i];

        REP(i,11)
        REP(j,101)
        REP(k,10001)
            dp[i][j][k] = -1;
        cout<<calc(A[0],A[1],A[2])<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new StrangeErrand();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0