結果

問題 No.158 奇妙なお使い
ユーザー IL_mstaIL_msta
提出日時 2017-02-28 23:39:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 3,625 bytes
コンパイル時間 1,785 ms
コンパイル使用メモリ 116,572 KB
実行使用メモリ 50,668 KB
最終ジャッジ日時 2023-09-12 11:13:12
合計ジャッジ時間 4,191 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
50,392 KB
testcase_01 AC 44 ms
50,568 KB
testcase_02 AC 46 ms
50,544 KB
testcase_03 AC 45 ms
50,492 KB
testcase_04 AC 72 ms
50,644 KB
testcase_05 AC 45 ms
50,592 KB
testcase_06 AC 45 ms
50,388 KB
testcase_07 AC 45 ms
50,556 KB
testcase_08 AC 46 ms
50,592 KB
testcase_09 AC 45 ms
50,540 KB
testcase_10 AC 45 ms
50,392 KB
testcase_11 AC 45 ms
50,444 KB
testcase_12 AC 45 ms
50,496 KB
testcase_13 AC 46 ms
50,512 KB
testcase_14 AC 45 ms
50,628 KB
testcase_15 AC 46 ms
50,556 KB
testcase_16 AC 45 ms
50,668 KB
testcase_17 AC 47 ms
50,492 KB
testcase_18 AC 51 ms
50,388 KB
testcase_19 AC 45 ms
50,384 KB
testcase_20 AC 45 ms
50,628 KB
testcase_21 AC 45 ms
50,388 KB
testcase_22 AC 46 ms
50,524 KB
testcase_23 AC 45 ms
50,536 KB
testcase_24 AC 45 ms
50,452 KB
testcase_25 AC 46 ms
50,392 KB
testcase_26 AC 45 ms
50,452 KB
testcase_27 AC 45 ms
50,580 KB
testcase_28 AC 45 ms
50,660 KB
testcase_29 AC 46 ms
50,380 KB
testcase_30 AC 46 ms
50,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region GNUC
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#pragma endregion

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;

// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}
////////////////////////////////
struct mon{
	int A,B,C;
};
bool operator<(mon m1,mon m2){
	if( m1.A<m2.A)return true;
	else if(m1.A>m2.A)return false;

	if( m1.B<m2.B)return true;
	else if(m1.B>m2.B)return false;

	if( m1.C<m2.C)return true;
	else if(m1.C>m2.C)return false;
	return false;
}
int eval(mon m){
	return m.A*1000+m.B*100+m.C;
}
mon pay(mon m,int D){
	mon ret;
	int temp = min(m.A,D/1000);
	if( temp < 0 ){
		mon ans={-1,-1,1};
		return ans;
	}
	ret.A = m.A - temp;
	D -= 1000*temp;

	temp = min(m.B,D/100);
	if( temp < 0 ){
		mon ans={-1,-1,1};
		return ans;
	}
	ret.B = m.B - temp;
	D -= 100 * temp;
	
	if( m.C < D ){
		mon ans={-1,-1,1};
		return ans;
	}
	ret.C = m.C - D;
	return ret;
}

mon nextIndex(mon src,mon now ){
	if( now.B ){
		now.B--;
		now.C+=100;
		return now;
	}
	now.B = (src.A-now.A)*10 + src.B;
	now.C = src.C;
	if( now.A ){
		now.A--;
		now.B += 10;
		return now;
	}
	now.A = -1;
	now.B = -1;
	now.C = -1;
	return now;
}
mon farstIndex(int m){
	mon ret;
	ret.A = m/1000;
	m -=ret.A*1000;
	ret.B = m/100;
	ret.C = m%100;
	return ret;
}

void solve(){
	
	vector< vector< vector<int> > > dp(11,vector< vector<int> >(101,vector<int>(10001,-1)) );
	mon start;
	cin >> start.A >> start.B >> start.C;
	dp[start.A][start.B][start.C] = 0;

	int D[2];
	mon P[2];
	for(int i=0;i<2;++i){
		cin >> D[i];
		cin >> P[i].A >> P[i].B >> P[i].C;
	}
	int ans = 0;
	
	int serVal = 10001;
	mon src = {0,0,10001};

	mon now = src;
	int i,j,k;
	while(true){
		now = nextIndex(src,now);
		if( now.A < 0 || now.B < 0 || now.C < 0 ){
			--serVal;
			if( serVal <= 0 ) break;
			src = farstIndex(serVal);
			now = src;
		}
		{
			i = now.A;
			j = now.B;
			k = now.C;
		}
		//cerr << i << " " << j << " " << k << endl;
		if( dp[i][j][k] < 0 ) continue;
		for(int p=0;p<2;++p){
			mon now={i,j,k};
			if( D[p] > eval(now) ) continue;
			mon next = pay(now,D[p]);
			if( next.A < 0 || next.B <0 || next.C < 0 ) continue;
			next.A += P[p].A;
			next.B += P[p].B;
			next.C += P[p].C;
			int nowVal = dp[i][j][k];
			int nextVal = dp[next.A][next.B][next.C];
			if( nextVal < nowVal+1 ){
				dp[next.A][next.B][next.C] = nowVal+1;
				if( ans < nowVal+1 ) ans = nowVal+1;
				//cerr << next.A << " " << next.B << " " << next.C << endl;
			}
		}
	}
	cout << ans << endl;
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}
0