結果

問題 No.158 奇妙なお使い
コンテスト
ユーザー T1610
提出日時 2026-10-14 19:02:12
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 498 ms / 5,000 ms
+ 40µs
コード長 2,278 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,044 ms
コンパイル使用メモリ 394,424 KB
実行使用メモリ 52,480 KB
最終ジャッジ日時 2026-10-14 19:02:26
合計ジャッジ時間 7,756 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (ll i = (s); i < (ll)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (ll i = (ll)(s - 1); i >= (ll)(e); i--)
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T, typename U>
T chmax(T& a, const U& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <typename T, typename U>
T chmin(T& a, const U& b) {
    if (a <= b) return false;
    a = b;
    return true;
}

void yes_no(bool f, string yes = "Yes", string no = "No") { cout << (f ? yes : no) << "\n"; }

void solve() {
    vi a(3);
    rep(i, 3) cin >> a[i];
    vi d(2);
    vector<vi> b(2, vi(3));
    rep(i, 2) {
        cin >> d[i];
        rep(j, 3) cin >> b[i][j];
    }
    map<vi, int> mp;
    using T = tuple<int, int, vi>;
    priority_queue<T> q;
    q.emplace(a[0] * 1000 + a[1] * 100 + a[2], 0, a);
    mp[a] = 0;
    int ans = 0;
    while (!q.empty()) {
        auto [x, y, z] = q.top();
        q.pop();
        if (mp[z] != y) continue;
        rep(i, 2) if (x >= d[i]) {
            int nx, ny;
            vi nz = z;
            nx = x - d[i] + b[i][0] * 1000 + b[i][1] * 100 + b[i][2];
            ny = y + 1;
            int r = d[i];
            if (r >= 1000) {
                int k = min(nz[0], r / 1000);
                nz[0] -= k;
                r -= k * 1000;
            }
            if (r >= 100) {
                int k = min(nz[1], r / 100);
                nz[1] -= k;
                r -= k * 100;
            }
            if (r >= 0) {
                int k = min(nz[2], r);
                nz[2] -= k;
                r -= k;
            }
            if (r != 0) continue;
            rep(j, 3) nz[j] += b[i][j];
            if (mp.count(nz) == 0 || mp[nz] < ny) {
                mp[nz] = ny;
                q.emplace(nx, ny, nz);
                chmax(ans, ny);
            }
        }
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t = 1;
    // multi-testcase
    // cin >> t;
    rep(ti, t) solve();
    return 0;
}
0