結果

問題 No.158 奇妙なお使い
ユーザー kimiyukikimiyuki
提出日時 2016-10-06 04:19:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 1,987 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 92,304 KB
実行使用メモリ 50,680 KB
最終ジャッジ日時 2023-09-12 06:28:11
合計ジャッジ時間 4,178 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
50,676 KB
testcase_01 AC 70 ms
50,676 KB
testcase_02 AC 69 ms
50,628 KB
testcase_03 AC 60 ms
50,244 KB
testcase_04 AC 70 ms
50,632 KB
testcase_05 AC 60 ms
50,300 KB
testcase_06 AC 51 ms
50,240 KB
testcase_07 AC 61 ms
50,244 KB
testcase_08 AC 70 ms
50,248 KB
testcase_09 AC 61 ms
50,248 KB
testcase_10 AC 60 ms
50,244 KB
testcase_11 AC 60 ms
50,296 KB
testcase_12 AC 61 ms
50,236 KB
testcase_13 AC 61 ms
50,620 KB
testcase_14 AC 70 ms
50,232 KB
testcase_15 AC 61 ms
50,240 KB
testcase_16 AC 71 ms
50,616 KB
testcase_17 AC 71 ms
50,280 KB
testcase_18 AC 62 ms
50,616 KB
testcase_19 AC 71 ms
50,612 KB
testcase_20 AC 61 ms
50,248 KB
testcase_21 AC 61 ms
50,292 KB
testcase_22 AC 61 ms
50,240 KB
testcase_23 AC 71 ms
50,676 KB
testcase_24 AC 71 ms
50,244 KB
testcase_25 AC 71 ms
50,248 KB
testcase_26 AC 82 ms
50,624 KB
testcase_27 AC 61 ms
50,680 KB
testcase_28 AC 62 ms
50,240 KB
testcase_29 AC 71 ms
50,300 KB
testcase_30 AC 71 ms
50,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
using namespace std;
template <class T> bool setmax(T & a, T const & b) { if (a < b) { a = b; return true; } else return false; }
template <typename T, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }
template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }
const int N = 10000, N0 = 1000, N1 = 100, N2 = 1;
int main() {
    int a0, a1, a2; cin >> a0 >> a1 >> a2;
    int db;         cin >> db;
    int b0, b1, b2; cin >> b0 >> b1 >> b2;
    int dc;         cin >> dc;
    int c0, c1, c2; cin >> c0 >> c1 >> c2;
    vector<vector<vector<int> > > dp = vectors(-1, N/N0+1, N/N1+1, N/N2+1);
    repeat (i,N/N0+1) repeat (j,N/N1+1) repeat (k,N/N2+1) dp[i][j][k] = -1;
    dp[a0][a1][a2] = 0;
    int ans = -1;
    while (true) {
        bool modified = false;
        repeat_reverse (i,N/N0+1) repeat_reverse (j,N/N1+1) repeat_reverse (k,N/N2+1) if (dp[i][j][k] != -1) {
            setmax(ans, dp[i][j][k]);
            auto foo = [&](int de, int e0, int e1, int e2) {
                int di = min(i, de / N0); de -= N0 * di;
                int dj = min(j, de / N1); de -= N1 * dj;
                int dk = min(k, de / N2); de -= N2 * dk;
                if (de == 0) {
                    if (setmax(dp[i-di+e0][j-dj+e1][k-dk+e2], dp[i][j][k] + 1)) {
                        modified = true;
                    }
                }
            };
            foo(db, b0, b1, b2);
            foo(dc, c0, c1, c2);
        }
        if (not modified) break;
    }
    cout << ans << endl;
    return 0;
}
0