結果

問題 No.158 奇妙なお使い
ユーザー tkzw_21tkzw_21
提出日時 2015-03-03 21:34:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 310 ms / 5,000 ms
コード長 1,212 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 156,644 KB
実行使用メモリ 31,916 KB
最終ジャッジ日時 2023-09-11 07:59:16
合計ジャッジ時間 3,477 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 310 ms
31,916 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 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,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 34 ms
7,476 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 7 ms
4,384 KB
testcase_22 AC 8 ms
4,572 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,pair<int,int>> PP;
typedef long long ll;

const double EPS = 1e-8;
const int INF = 1e9;
const int MOD = 1e9+7;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};

int Db,Dc;
vector<int> A,B,C;

map<tuple<int,int,int>,int>memo;
int dfs(int A1000,int A100,int A1){
	int ret = 0;
	tuple<int,int,int> tp(A1000,A100,A1);
	if(memo[tp] != 0){
		return memo[tp];
	}

	int db = Db;
	int a1000 = A1000,a100 = A100,a1 = A1;
	while(db >= 1000 && a1000 > 0){db -= 1000;a1000--;}
	while(db >= 100 && a100 > 0){db -= 100;a100--;}
	int t = min(a1,db);
	a1 -= t;
	db -= t;
	if(db == 0)ret = max(ret,dfs(a1000+B[0],a100+B[1],a1+B[2]));

	int dc = Dc;
	a1000 = A1000;a100 = A100;a1 = A1;
	while(dc >= 1000 && a1000 > 0){dc -= 1000;a1000--;}
	while(dc >= 100 && a100 > 0){dc -= 100;a100--;}
	t = min(a1,dc);
	a1 -= t;
	dc -= t;
	if(dc == 0)ret = max(ret,dfs(a1000+C[0],a100+C[1],a1+C[2]));
	
	return memo[tp] = ret + 1;
}

int main(void) {
	A.resize(3);B.resize(3);C.resize(3);
	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];

	cout << dfs(A[0],A[1],A[2])-1 << endl;

	return 0;
}
0