結果

問題 No.158 奇妙なお使い
ユーザー IL_mstaIL_msta
提出日時 2017-02-28 23:13:07
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 3,173 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 118,124 KB
実行使用メモリ 55,056 KB
最終ジャッジ日時 2023-09-02 18:11:27
合計ジャッジ時間 13,811 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
50,516 KB
testcase_01 AC 57 ms
50,508 KB
testcase_02 AC 52 ms
50,500 KB
testcase_03 AC 51 ms
50,600 KB
testcase_04 AC 3,452 ms
50,480 KB
testcase_05 AC 51 ms
50,416 KB
testcase_06 AC 50 ms
50,516 KB
testcase_07 AC 51 ms
50,376 KB
testcase_08 AC 51 ms
50,508 KB
testcase_09 AC 51 ms
50,572 KB
testcase_10 AC 55 ms
50,480 KB
testcase_11 AC 54 ms
50,508 KB
testcase_12 AC 52 ms
50,376 KB
testcase_13 AC 51 ms
50,520 KB
testcase_14 AC 147 ms
50,384 KB
testcase_15 AC 71 ms
50,512 KB
testcase_16 AC 60 ms
50,608 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
}

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;
	for(int i=10;i>=0;--i){
	for(int j=100;j>=0;--j){
	for(int k=10000;k>=0;--k){

		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;
				if( (i < next.A) ||
					( i == next.A && j < next.B )||
					( i == next.A && j == next.B && k < next.C )
				)
				{
					i = next.A;
					j = next.B;
					k = next.C+1;
				}
			}
		}
	}}}
	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