結果

問題 No.158 奇妙なお使い
ユーザー 👑 kmjpkmjp
提出日時 2015-02-26 23:55:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 598 ms / 5,000 ms
コード長 2,146 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 167,676 KB
実行使用メモリ 45,152 KB
最終ジャッジ日時 2023-09-11 07:52:00
合計ジャッジ時間 3,518 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 598 ms
45,152 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 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,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 67 ms
10,064 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 10 ms
4,676 KB
testcase_22 AC 10 ms
4,616 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 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 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;
vector<pair<pair<int,int>,int> > V[10001];
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;
	V[A[0]*1000+A[1]*100+A[2]].push_back(h(A[0],A[1],A[2]));
	
	for(i=10000;i>=0;i--) {
		sort(V[i].begin(),V[i].end());
		
		FOR(y,V[i].size()) {
			if(y>0 && V[i][y]==V[i][y-1]) continue;
			ma=max(ma,M[V[i][y]]);
			{
				pair<pair<int,int>,int> k=V[i][y],k2;
				int x=DB;
				j=min(x/1000,k.first.first);
				k.first.first -= j; x -= j*1000;
				j=min(x/100,k.first.second);
				k.first.second -= j; x -= j*100;
				j=min(x,k.second);
				k.second -= j; x -= j;
				if(x==0) {
					k2=h(k.first.first+B[0],k.first.second+B[1],k.second+B[2]);
					r=k2.first.first*1000+k2.first.second*100+k2.second;
					M[k2]=max(M[k2],M[V[i][y]]+1);
					V[r].push_back(k2);
				}
			}
			{
				pair<pair<int,int>,int> k=V[i][y],k2;
				int x=DC;
				j=min(x/1000,k.first.first);
				k.first.first -= j; x -= j*1000;
				j=min(x/100,k.first.second);
				k.first.second -= j; x -= j*100;
				j=min(x,k.second);
				k.second -= j; x -= j;
				if(x==0) {
					k2=h(k.first.first+C[0],k.first.second+C[1],k.second+C[2]);
					r=k2.first.first*1000+k2.first.second*100+k2.second;
					M[k2]=max(M[k2],M[V[i][y]]+1);
					V[r].push_back(k2);
				}
			}
		}
	}
	
	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