結果
問題 |
No.158 奇妙なお使い
|
ユーザー |
![]() |
提出日時 | 2022-12-25 18:18:38 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 5,000 ms |
コード長 | 1,130 bytes |
コンパイル時間 | 3,898 ms |
コンパイル使用メモリ | 146,280 KB |
実行使用メモリ | 51,200 KB |
最終ジャッジ日時 | 2024-11-19 08:01:17 |
合計ジャッジ時間 | 6,244 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include <iostream> #include <vector> #include <cmath> #include <map> #include <set> #include <iomanip> #include <queue> #include <algorithm> #include <numeric> #include <deque> using namespace std; vector<vector<vector<int>>> ans; int ax, ay, az, db, bx, by, bz, dc, cx, cy, cz; tuple<int, int, int> g(int i, int j, int k, int d){ int x, y, z; x = min(d / 1000, i); d -= x * 1000; y = min(d / 100, j); d -= y * 100; z = min(d , k); d -= z; if (d == 0) return make_tuple(x, y, z); else return make_tuple(-1, -1, -1); } int f(int i, int j, int k){ if (i == 0 && j == 0 && k == 0) return 0; if (ans[i][j][k] != -1) return ans[i][j][k]; int a, b, c, mx = 0; tie(a, b, c) = g(i, j, k, db); if (a != -1) mx = max(mx, f(i-a+bx, j-b+by, k-c+bz)+1); tie(a, b, c) = g(i, j, k, dc); if (a != -1) mx = max(mx, f(i-a+cx, j-b+cy, k-c+cz)+1); return ans[i][j][k] = mx; } int main(){ cin >> ax >> ay >> az >> db >> bx >> by >> bz >> dc >> cx >> cy >> cz; ans.resize(11, vector(101, vector<int>(10001, -1))); cout << f(ax, ay, az) << endl; return 0; }