結果

問題 No.158 奇妙なお使い
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-14 01:03:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,977 bytes
コンパイル時間 2,628 ms
コンパイル使用メモリ 167,904 KB
実行使用メモリ 33,696 KB
最終ジャッジ日時 2023-09-17 20:05:00
合計ジャッジ時間 3,106 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;


int A[3], B[3], C[3];
int now[3];
int DB, DC;

bool useB(){
	int nokori = DB;
	int use0 = min(now[0], nokori / 1000);
	nokori -= use0 * 1000;
	int use1 = min(now[1], nokori / 100);
	nokori -= use1 * 100;
	int use2 = min(now[2], nokori / 1);
	nokori -= use2 * 1;
	if (nokori != 0) return false;
	now[0] += B[0] - use0;
	now[1] += B[1] - use1;
	now[2] += B[2] - use2;
	return true;
}

bool useC(){
	int nokori = DC;
	int use0 = min(now[0], nokori / 1000);
	nokori -= use0 * 1000;
	int use1 = min(now[1], nokori / 100);
	nokori -= use1 * 100;
	int use2 = min(now[2], nokori / 1);
	nokori -= use2 * 1;
	if (nokori != 0) return false;
	now[0] += C[0] - use0;
	now[1] += C[1] - use1;
	now[2] += C[2] - use2;
	return true;
}

int main() {
	cin >> A[0] >> A[1] >> A[2];
	cin >> DB;
	cin >> B[0] >> B[1] >> B[2];
	cin >> DC;
	cin >> C[0] >> C[1] >> C[2];

	auto first = make_tuple(A[0] * 1000 + A[1] * 100 + A[2], 0, A[0], A[1], A[2]);


	priority_queue<tuple<int, int, int, int, int>> pq;
	pq.push(first);
	set<tuple<int, int, int>> s;
	set<tuple<int, int, int, int, int>> s2;

	int ans = 0;
	while (pq.size()){
		auto i = pq.top(); pq.pop();
		now[0] = get<2>(i);
		now[1] = get<3>(i);
		now[2] = get<4>(i);
		ans = max(ans, get<1>(i));
		//cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << " " << get<3>(i) << " " << get<4>(i) << endl;
		if (s.count(make_tuple(now[0], now[1], now[2]))) continue;
		s.insert(make_tuple(now[0], now[1], now[2]));

		if (useB()){
			auto n = make_tuple(now[0] * 1000 + now[1]*100+now[2], get<1>(i) + 1, now[0], now[1], now[2]);
			if (s2.count(n) == 0){
				pq.push(n);
				s2.insert(n);
				now[0] = get<2>(i);
				now[1] = get<3>(i);
				now[2] = get<4>(i);
			}
		}
		if (useC()){
			auto n = make_tuple(now[0] * 1000 + now[1] * 100 + now[2], get<1>(i) +1, now[0], now[1], now[2]);
			if (s2.count(n) == 0){
				s2.insert(n);
				pq.push(n);
			}
		}
	}
	cout << ans << endl;
	cin >> ans;
}
0