結果

問題 No.158 奇妙なお使い
ユーザー roiti46roiti46
提出日時 2015-03-01 18:34:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 256 ms / 5,000 ms
コード長 1,243 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 52,892 KB
実行使用メモリ 47,436 KB
最終ジャッジ日時 2023-09-11 07:55:04
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
46,900 KB
testcase_01 AC 17 ms
46,744 KB
testcase_02 AC 17 ms
46,784 KB
testcase_03 AC 16 ms
46,756 KB
testcase_04 AC 256 ms
47,436 KB
testcase_05 AC 17 ms
46,776 KB
testcase_06 AC 17 ms
46,800 KB
testcase_07 AC 17 ms
46,760 KB
testcase_08 AC 17 ms
46,740 KB
testcase_09 AC 17 ms
46,792 KB
testcase_10 AC 17 ms
46,744 KB
testcase_11 AC 17 ms
47,036 KB
testcase_12 AC 18 ms
46,816 KB
testcase_13 AC 17 ms
46,760 KB
testcase_14 AC 17 ms
46,784 KB
testcase_15 AC 18 ms
47,048 KB
testcase_16 AC 17 ms
46,852 KB
testcase_17 AC 20 ms
46,784 KB
testcase_18 AC 20 ms
46,828 KB
testcase_19 AC 17 ms
46,784 KB
testcase_20 AC 17 ms
46,828 KB
testcase_21 AC 17 ms
46,936 KB
testcase_22 AC 18 ms
47,348 KB
testcase_23 AC 17 ms
47,000 KB
testcase_24 AC 17 ms
46,736 KB
testcase_25 AC 17 ms
46,744 KB
testcase_26 AC 18 ms
46,788 KB
testcase_27 AC 17 ms
46,824 KB
testcase_28 AC 19 ms
46,736 KB
testcase_29 AC 18 ms
47,048 KB
testcase_30 AC 21 ms
46,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define REP(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) REP(i,0,a)
using namespace std;

int A1, A2, A3, B1, B2, B3, C1, C2, C3;
int x1, x2, x3, db, dc, Db, Dc;
int memo[11][101][10001];

int solve(int a1, int a2, int a3) {
    if (memo[a1][a2][a3] >= 0) return memo[a1][a2][a3];
    int res = 0;
    if (1000*a1+100*a2+a3 >= Db) {
        x1 = a1, x2 = a2, x3 = a3, db = Db;
        while (x1 && db >= 1000) db -= 1000, x1 -= 1;
        while (x2 && db >=  100) db -=  100, x2 -= 1;
        while (x3 && db >=    1) db -=    1, x3 -= 1;
        if (db == 0) res = max(res, solve(x1+B1, x2+B2, x3+B3)+1);
    }

    if (1000*a1+100*a2+a3 >= Dc) {
        x1 = a1, x2 = a2, x3 = a3, dc = Dc;
        while (x1 && dc >= 1000) dc -= 1000, x1 -= 1;
        while (x2 && dc >=  100) dc -=  100, x2 -= 1;
        while (x3 && dc >=    1) dc -=    1, x3 -= 1;
        if (dc == 0) res = max(res, solve(x1+C1, x2+C2, x3+C3)+1);
    }
    return memo[a1][a2][a3] = res;
}

int main(void){
    cin >> A1 >> A2 >> A3;
    cin >> Db;
    cin >> B1 >> B2 >> B3;
    cin >> Dc;
    cin >> C1 >> C2 >> C3;
    
    rep(i, 11) rep(j, 101) rep(k, 10001) memo[i][j][k] = -1;
    cout << solve(A1, A2, A3) << endl;
    return 0;
}
0