結果
| 問題 |
No.158 奇妙なお使い
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2017-02-28 23:39:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 5,000 ms |
| コード長 | 3,625 bytes |
| コンパイル時間 | 1,651 ms |
| コンパイル使用メモリ | 121,316 KB |
| 実行使用メモリ | 50,688 KB |
| 最終ジャッジ日時 | 2024-06-29 23:47:07 |
| 合計ジャッジ時間 | 4,171 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#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();
}
IL_msta