結果

問題 No.158 奇妙なお使い
ユーザー 👑 kmjpkmjp
提出日時 2015-02-27 00:16:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 800 ms / 5,000 ms
コード長 1,513 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 158,496 KB
実行使用メモリ 59,936 KB
最終ジャッジ日時 2023-09-11 07:52:43
合計ジャッジ時間 3,475 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,504 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 800 ms
59,936 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,400 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 8 ms
4,708 KB
testcase_18 AC 83 ms
11,952 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 13 ms
5,080 KB
testcase_22 AC 13 ms
5,144 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 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 6 ms
4,656 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))
//-------------------------------------------------------



struct S {
	int a,b,c;
	S(int _a,int _b,int _c){ a=_a, b=_b, c=_c;}
	int val(){ return a*1000+b*100+c;};
};
struct cmp {
bool operator()(const S& a, const S& b) const {
	return a.a<b.a || (a.a==b.a && (a.b<b.b || (a.b==b.b && a.c<b.c)));  };
};

int A[3],B[2][3];
int D[2];
int ma;
set<S,cmp> V[10001];
map<S,int,cmp> M;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A[0]>>A[1]>>A[2];
	FOR(i,2) cin>>D[i]>>B[i][0]>>B[i][1]>>B[i][2];
	
	S f(A[0],A[1],A[2]);
	M[f]=0;
	V[f.val()].insert(f);
	
	for(i=10000;i>=0;i--) {
		ITR(it,V[i]) {
			ma=max(ma,M[*it]);
			FOR(j,2) {
				S k=*it;
				
				x=D[j];
				r=min(x/1000,k.a); k.a -= r; x -= r*1000;
				r=min(x/100,k.b);  k.b -= r; x -= r*100;
				r=min(x,k.c);      k.c -= r; x -= r;
				if(x==0) {
					S k2(k.a+B[j][0],k.b+B[j][1],k.c+B[j][2]);
					M[k2]=max(M[k2],M[*it]+1);
					V[k2.val()].insert(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