結果

問題 No.158 奇妙なお使い
ユーザー fiordfiord
提出日時 2015-08-25 00:10:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 636 ms / 5,000 ms
コード長 1,659 bytes
コンパイル時間 2,061 ms
コンパイル使用メモリ 169,488 KB
実行使用メモリ 59,376 KB
最終ジャッジ日時 2023-09-11 12:12:18
合計ジャッジ時間 4,073 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int dp[11][101][10001];
bool use[11][101][10001];
tuple<int,int,int> ok(int a,int th,int hu,int on){
	int dig1=min(th,a/1000);
	th-=dig1;	a-=dig1*1000;
	int dig2=min(hu,a/100);
	hu-=dig2;	a-=dig2*100;
	int dig3=min(on,a);
	on-=dig3;	a-=dig3;
	if(a!=0)	return make_tuple(-1,-1,-1);
	return make_tuple(th,hu,on);
}
int main(){
	int a[3];	cin>>a[0]>>a[1]>>a[2];
	int db;	cin>>db;
	int b[3];	cin>>b[0]>>b[1]>>b[2];
	int dc;	cin>>dc;
	int c[3];	cin>>c[0]>>c[1]>>c[2];
	int ans=0;
	priority_queue<tuple<int,int,int,int,int> > q;
	q.push(make_tuple(a[0]*1000+a[1]*100+a[2],0,a[0],a[1],a[2]));
	set<tuple<int,int,int,int,int>> s;
	set<tuple<int,int,int>> use;
	while(!q.empty()){
		auto n=q.top();	q.pop();
		int point=get<1>(n);
		int th=get<2>(n);
		int hu=get<3>(n);
		int on=get<4>(n);
		ans=max(ans,point);
		if(use.find(make_tuple(th,hu,on))!=use.end())	continue;
		use.insert(make_tuple(th,hu,on));
		auto test=ok(db,th,hu,on);
		if(get<0>(test)!=-1){
			int nt=get<0>(test)+b[0];
			int nh=get<1>(test)+b[1];
			int no=get<2>(test)+b[2];
			if(s.find(make_tuple(nt*1000+nh*100+no,point+1,nt,nh,no))==s.end()){
				s.insert(make_tuple(nt*1000+nh*100+no,point+1,nt,nh,no));
				q.push(make_tuple(nt*1000+nh*100+no,point+1,nt,nh,no));
			}
		}
		test=ok(dc,th,hu,on);
		if(get<0>(test)!=-1){
			int nt=get<0>(test)+c[0];
			int nh=get<1>(test)+c[1];
			int no=get<2>(test)+c[2];
			if(s.find(make_tuple(nt*1000+nh*100+no,point+1,nt,nh,no))==s.end()){
				s.insert(make_tuple(nt*1000+nh*100+no,point+1,nt,nh,no));
				q.push(make_tuple(nt*1000+nh*100+no,point+1,nt,nh,no));
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
0