結果
問題 | No.158 奇妙なお使い |
ユーザー |
![]() |
提出日時 | 2015-03-03 21:34:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 275 ms / 5,000 ms |
コード長 | 1,212 bytes |
コンパイル時間 | 1,979 ms |
コンパイル使用メモリ | 171,388 KB |
実行使用メモリ | 32,384 KB |
最終ジャッジ日時 | 2024-06-28 22:31:19 |
合計ジャッジ時間 | 2,816 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#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; }