結果

問題 No.158 奇妙なお使い
ユーザー kurenai3110kurenai3110
提出日時 2016-11-15 17:43:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 612 ms / 5,000 ms
コード長 1,508 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 69,064 KB
実行使用メモリ 5,904 KB
最終ジャッジ日時 2023-09-12 07:09:54
合計ジャッジ時間 3,218 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 26 ms
5,904 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 11 ms
5,424 KB
testcase_18 AC 8 ms
4,896 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 407 ms
4,380 KB
testcase_22 AC 612 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

struct MONEY{
	int c1000, c100, c1,cnt;
};

int DP[11][101][10001];

int main()
{
	vector<int>A(3);
	cin >> A[0] >> A[1] >> A[2];
	int Db; cin >> Db;
	vector<int>B(3);
	cin >> B[0] >> B[1] >> B[2];
	int Dc; cin >> Dc;
	vector<int>C(3);
	cin >> C[0] >> C[1] >> C[2];

	queue<MONEY> que;
	que.push({ A[0], A[1], A[2] , 0 });

	int maxCnt = 0;
	while (!que.empty()){
		int b = Db, c = Dc;
		MONEY Co = que.front(); que.pop();
		maxCnt = max(maxCnt, Co.cnt);
		if (DP[Co.c1000][Co.c100][Co.c1] != 0 && DP[Co.c1000][Co.c100][Co.c1] >= maxCnt)continue;
		else DP[Co.c1000][Co.c100][Co.c1] = maxCnt;

		int c1000 = Co.c1000, c100 = Co.c100, c1 = Co.c1;
		for (int i = c1000; i > 0; i--){
			if (b >= 1000 * i){
				b -= 1000 * i;
				c1000 -= i;
				break;
			}
		}
		for (int i = c100; i > 0; i--){
			if (b >= 100 * i){
				b -= 100 * i;
				c100 -= i;
				break;
			}
		}
		if (c1 >= b){
			c1 -= b;
			b = 0;
		}

		if (b == 0) que.push({ c1000+B[0], c100+B[1], c1+B[2] , Co.cnt+1 });

		c1000 = Co.c1000, c100 = Co.c100, c1 = Co.c1;
		for (int i = c1000; i > 0; i--){
			if (c >= 1000 * i){
				c -= 1000 * i;
				c1000 -= i;
				break;
			}
		}
		for (int i = c100; i > 0; i--){
			if (c >= 100 * i){
				c -= 100 * i;
				c100 -= i;
				break;
			}
		}
		if (c1 >= c){
			c1 -= c;
			c = 0;
		}
		if (c == 0) que.push({ c1000 + C[0], c100+C[1], c1+C[2] , Co.cnt+1 });
	}

	cout << maxCnt << endl;

	return 0;
}
0