結果
問題 |
No.158 奇妙なお使い
|
ユーザー |
![]() |
提出日時 | 2015-08-25 00:10:14 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 645 ms / 5,000 ms |
コード長 | 1,659 bytes |
コンパイル時間 | 1,628 ms |
コンパイル使用メモリ | 181,972 KB |
実行使用メモリ | 59,136 KB |
最終ジャッジ日時 | 2024-06-29 02:41:56 |
合計ジャッジ時間 | 3,413 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#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; }