結果

問題 No.158 奇妙なお使い
ユーザー kmjp
提出日時 2015-02-26 23:39:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
MLE  
実行時間 -
コード長 1,821 bytes
コンパイル時間 1,810 ms
コンパイル使用メモリ 175,900 KB
実行使用メモリ 816,576 KB
最終ジャッジ日時 2024-06-23 21:38:37
合計ジャッジ時間 8,531 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 4 MLE * 1 -- * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

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

int ma;
map<pair<pair<int,int>,int>,int> M;


pair<pair<int,int>,int> h(int a,int b,int c) {
	return make_pair(make_pair(a,b),c);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	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];
	
	M[h(A[0],A[1],A[2])]=0;
	queue<pair<pair<int,int>,int> > q;
	q.push(h(A[0],A[1],A[2]));
	while(q.size()) {
		pair<pair<int,int>,int> k=q.front(),k2=k;
		q.pop();
		ma=max(ma,M[k]);
		
		int x=DB;
		i=min(x/1000,k.first.first);
		k.first.first -= i; x -= i*1000;
		i=min(x/100,k.first.second);
		k.first.second -= i; x -= i*100;
		i=min(x,k.second);
		k.second -= i; x -= i;
		if(x==0) {
			M[h(k.first.first+B[0],k.first.second+B[1],k.second+B[2])]=ma+1;
			q.push(h(k.first.first+B[0],k.first.second+B[1],k.second+B[2]));
		}
		
		k=k2;
		x=DC;
		i=min(x/1000,k.first.first);
		k.first.first -= i; x -= i*1000;
		i=min(x/100,k.first.second);
		k.first.second -= i; x -= i*100;
		i=min(x,k.second);
		k.second -= i; x -= i;
		if(x==0) {
			M[h(k.first.first+C[0],k.first.second+C[1],k.second+C[2])]=ma+1;
			q.push(h(k.first.first+C[0],k.first.second+C[1],k.second+C[2]));
		}
	}
	
	
	
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0