結果

問題 No.158 奇妙なお使い
ユーザー roiti46roiti46
提出日時 2015-03-01 18:24:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 393 ms / 5,000 ms
コード長 1,593 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 53,032 KB
実行使用メモリ 6,364 KB
最終ジャッジ日時 2023-09-11 07:54:55
合計ジャッジ時間 2,867 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,376 KB
testcase_01 AC 12 ms
4,380 KB
testcase_02 AC 12 ms
4,376 KB
testcase_03 AC 11 ms
4,380 KB
testcase_04 AC 393 ms
6,364 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 11 ms
4,376 KB
testcase_07 AC 11 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 11 ms
4,380 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 12 ms
4,380 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 148 ms
5,472 KB
testcase_18 AC 15 ms
5,144 KB
testcase_19 AC 11 ms
4,384 KB
testcase_20 AC 39 ms
4,376 KB
testcase_21 AC 300 ms
4,380 KB
testcase_22 AC 12 ms
4,380 KB
testcase_23 AC 12 ms
4,380 KB
testcase_24 AC 12 ms
4,376 KB
testcase_25 AC 12 ms
4,376 KB
testcase_26 AC 12 ms
4,376 KB
testcase_27 AC 12 ms
4,376 KB
testcase_28 AC 15 ms
4,376 KB
testcase_29 AC 12 ms
4,376 KB
testcase_30 AC 17 ms
4,380 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];

void solve(int a1, int a2, int a3, int n) {
    if (memo[a1][a2][a3] > n) return;
    if (1000*a1+100*a2+a3 >= Db) {
        x1 = a1, x2 = a2, x3 = a3, db = Db;
        rep(i, a1) {
            if (db >= 1000) db -= 1000, x1 -= 1;
            else break;
        }
        rep(i, a2) {
            if (db >= 100) db -= 100, x2 -= 1;
            else break;
        }
        rep(i, a3) {
            if (db >= 1) db -= 1, x3 -= 1;
            else break;
        }
        if (db == 0) {
            memo[a1][a2][a3] = n+1;
            solve(x1+B1, x2+B2, x3+B3, n+1);
        }
    }

    if (1000*a1+100*a2+a3 >= Dc) {
        x1 = a1, x2 = a2, x3 = a3, dc = Dc;
        rep(i, a1) {
            if (dc >= 1000) dc -= 1000, x1 -= 1;
            else break;
        }
        rep(i, a2) {
            if (dc >= 100) dc -= 100, x2 -= 1;
            else break;
        }
        rep(i, a3) {
            if (dc >= 1) dc -= 1, x3 -= 1;
            else break;
        }
        if (dc == 0) {
            memo[a1][a2][a3] = n+1;
            solve(x1+C1, x2+C2, x3+C3, n+1);
        }
    }   
}

int main(void){
    cin >> A1 >> A2 >> A3;
    cin >> Db;
    cin >> B1 >> B2 >> B3;
    cin >> Dc;
    cin >> C1 >> C2 >> C3;

    solve(A1,A2,A3,0);

    int ans = 0;
    rep(i,11) rep(j,101) rep(k,10001) ans = max(ans, memo[i][j][k]);
    cout << ans << endl;
    return 0;
}
0