結果

問題 No.158 奇妙なお使い
ユーザー mamekinmamekin
提出日時 2015-04-12 12:02:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 957 ms / 5,000 ms
コード長 1,948 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 96,128 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 10:59:04
合計ジャッジ時間 5,642 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 25 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 936 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 20 ms
4,380 KB
testcase_16 AC 22 ms
4,380 KB
testcase_17 AC 85 ms
4,380 KB
testcase_18 AC 158 ms
4,376 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 47 ms
4,376 KB
testcase_21 AC 957 ms
4,376 KB
testcase_22 AC 957 ms
4,376 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 14 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 13 ms
4,380 KB
testcase_29 AC 14 ms
4,376 KB
testcase_30 AC 60 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int coin[] = {1000, 100, 1};

bool check(const vector<int>& a, int d)
{
    for(int i=0; i<3; ++i){
        int x = min(a[i], d / coin[i]);
        d -= x * coin[i];
    }
    return d == 0;
}

void sub(vector<int>& a, int d)
{
    for(int i=0; i<3; ++i){
        int x = min(a[i], d / coin[i]);
        d -= x * coin[i];
        a[i] -= x;
    }
}

void add(vector<int>& a, const vector<int>& b)
{
    for(int i=0; i<3; ++i)
        a[i] += b[i];
}

int main()
{
    vector<int> init(3);
    for(int i=0; i<3; ++i)
        cin >> init[i];

    vector<int> value(2);
    vector<vector<int> > receive(2, vector<int>(3));
    for(int i=0; i<2; ++i){
        cin >> value[i];
        for(int j=0; j<3; ++j)
            cin >> receive[i][j];
    }

    vector<vector<int> > dp(11, vector<int>(101, -1));
    dp[init[0]][init[1]] = init[2];
    int ans = 0;
    for(;;){
        vector<vector<int> > nextDp(11, vector<int>(101, -1));
        bool ok = false;
        for(int i=0; i<=10; ++i){
            for(int j=0; j<=100; ++j){
                for(int a=0; a<2; ++a){
                    vector<int> v = {i, j, dp[i][j]};
                    if(check(v, value[a])){
                        sub(v, value[a]);
                        add(v, receive[a]);
                        nextDp[v[0]][v[1]] = max(nextDp[v[0]][v[1]], v[2]);
                        ok = true;
                    }
                }
            }
        }

        if(!ok){
            cout << ans << endl;
            return 0;
        }
        dp.swap(nextDp);
        ++ ans;
    }
}
0