結果

問題 No.158 奇妙なお使い
ユーザー nanophoto12nanophoto12
提出日時 2016-01-03 09:17:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 523 ms / 5,000 ms
コード長 2,304 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 74,196 KB
実行使用メモリ 47,640 KB
最終ジャッジ日時 2023-09-11 23:01:14
合計ジャッジ時間 3,649 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
46,832 KB
testcase_01 AC 19 ms
46,824 KB
testcase_02 AC 17 ms
46,820 KB
testcase_03 AC 17 ms
46,788 KB
testcase_04 AC 523 ms
47,640 KB
testcase_05 AC 17 ms
46,812 KB
testcase_06 AC 17 ms
46,780 KB
testcase_07 AC 16 ms
47,012 KB
testcase_08 AC 17 ms
46,768 KB
testcase_09 AC 17 ms
46,768 KB
testcase_10 AC 17 ms
46,816 KB
testcase_11 AC 17 ms
46,820 KB
testcase_12 AC 16 ms
46,724 KB
testcase_13 AC 17 ms
46,736 KB
testcase_14 AC 19 ms
46,716 KB
testcase_15 AC 27 ms
46,796 KB
testcase_16 AC 24 ms
46,828 KB
testcase_17 AC 68 ms
46,928 KB
testcase_18 AC 23 ms
46,844 KB
testcase_19 AC 17 ms
46,760 KB
testcase_20 AC 20 ms
46,880 KB
testcase_21 AC 17 ms
47,040 KB
testcase_22 AC 18 ms
47,516 KB
testcase_23 AC 18 ms
46,964 KB
testcase_24 AC 17 ms
46,768 KB
testcase_25 AC 17 ms
46,708 KB
testcase_26 AC 19 ms
46,728 KB
testcase_27 AC 17 ms
46,724 KB
testcase_28 AC 39 ms
46,820 KB
testcase_29 AC 17 ms
46,772 KB
testcase_30 AC 41 ms
46,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define FOR(x,y) for(int x = 0;x < (y);x++)
#define LLI long long int
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())

#define _L(x) cout<<(x)<<endl
//#define _L(x) ;

template<int um> class UF {
public:
    vector<int> _parent,_rank;
    UF()
    {
        _parent=_rank=vector<int>(um,0);
        for(int i=0;i<um;i++)
        {
            _parent[i]=i;
        }
    }
    
    int Find(int x)
    {
        if(_parent[x] == x)
        {
            return x;
        }
        _parent[x] = Find(_parent[x]);
        return _parent[x];
    }
    
    int Union(int x,int y)
    {
        int xRoot = Find(x);
        int yRoot = Find(y);
        if(_rank[xRoot]>_rank[yRoot])
        {
            _parent[xRoot] = yRoot;
           return yRoot;
        }
        if(_rank[xRoot]<_rank[yRoot])
        {
            _parent[yRoot] = xRoot;
            return xRoot;
        }
        if(xRoot != yRoot)
        {
            _parent[yRoot] = xRoot;
            _rank[xRoot]++;
            return xRoot;
        }
        return xRoot;
    }
};

int dp[11][101][10001];
int A1000, A100, A1;
int Db;
int B1000, B100, B1;
int Dc;
int C1000, C100, C1;

int calculate(int a, int b, int c)
{
    if(dp[a][b][c] >= 0)
    {
        return dp[a][b][c];
    }
    int maxValue = 0;
    FOR(i, a+1) FOR(j, b + 1)
    {
        int restB = Db - i * 1000 - j * 100;
        if(restB >= 0 && restB <= c)
        {
            maxValue = max(maxValue, calculate(a - i + B1000, b - j + B100, c - restB + B1) + 1);
        }
        int restC = Dc - i * 1000 - j * 100;
        if(restC >= 0 && restC <= c)
        {
            maxValue = max(maxValue, calculate(a - i + C1000, b - j + C100, c - restC + C1) + 1);
        }
    }
    dp[a][b][c] = maxValue;
    return maxValue;
}

int main() {
    
    cin >> A1000 >> A100>> A1;
    cin >> Db;
    cin >> B1000 >> B100>> B1;
    cin >> Dc;
    cin >> C1000 >> C100>> C1;

    FOR(i, 11) FOR(j, 101) FOR(k, 10001)
    {
        dp[i][j][k] = -1;
    }
    
    cout << calculate(A1000, A100, A1) << endl;
    return 0;
}
0