結果
| 問題 |
No.158 奇妙なお使い
|
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2016-09-27 22:25:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 348 ms / 5,000 ms |
| コード長 | 1,859 bytes |
| コンパイル時間 | 1,778 ms |
| コンパイル使用メモリ | 179,504 KB |
| 実行使用メモリ | 32,896 KB |
| 最終ジャッジ日時 | 2024-06-29 19:31:22 |
| 合計ジャッジ時間 | 2,774 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
namespace {
typedef double real;
typedef long long ll;
template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
if (vs.empty()) return os << "[]";
auto i = vs.begin();
os << "[" << *i;
for (++i; i != vs.end(); ++i) os << " " << *i;
return os << "]";
}
template<class T> istream& operator>>(istream& is, vector<T>& vs) {
for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
return is;
}
vector<int> A, B, C;
int Db, Dc;
void input() {
A.resize(3);
B.resize(3);
C.resize(3);
cin >> A >> Db >> B >> Dc >> C;
}
vector<int> try_(int d, int x, int y, int z) {
vector<int> ret;
int t = d;
int p = min(x, t / 1000);
t -= p * 1000;
int q = min(y, t / 100);
t -= q * 100;
int r = min(z, t / 1);
if (p * 1000 + q * 100 + r * 1 < d) return ret;
ret.push_back(p);
ret.push_back(q);
ret.push_back(r);
return ret;
}
map< tuple<int, int, int>, int > cache;
int f(int x, int y, int z) {
//cerr << "f " << x << " " << y << " " << z << endl;
auto key = make_tuple(x, y, z);
if (cache.count(key)) return cache[key];
vector<int> b = try_(Db, x, y, z);
vector<int> c = try_(Dc, x, y, z);
int ans = 0;
if (not b.empty()) {
ans = max(ans, 1 + f(x - b[0] + B[0], y - b[1] + B[1], z - b[2] + B[2]));
}
if (not c.empty()) {
ans = max(ans, 1 + f(x - c[0] + C[0], y - c[1] + C[1], z - c[2] + C[2]));
}
return cache[key] = ans;
}
void solve() {
cout << f(A[0], A[1], A[2]) << endl;
}
}
int main() {
input(); solve();
return 0;
}
izuru_matsuura