結果

問題 No.3696 Betting Machine
コンテスト
ユーザー passpin
提出日時 2026-08-14 21:24:57
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 15 ms / 1,500 ms
+ 799µs
コード長 2,292 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,170 ms
コンパイル使用メモリ 181,756 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-09 20:50:29
合計ジャッジ時間 2,464 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
 
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int S, T, N;
    cin >> S >> T >> N;
 
    array<int, 3> P{}, A{}, B{};
    for (int i = 0; i < 3; ++i) {
        cin >> P[i] >> A[i] >> B[i];
    }
 
    array<long long, 10> pow100{};
    pow100[0] = 1;
    for (int i = 1; i <= N; ++i) {
        pow100[i] = pow100[i - 1] * 100LL;
    }
 
    // Precompute the balance change caused by each outcome and wager.
    vector<array<int, 3>> change(T);
    for (int x = 1; x < T; ++x) {
        for (int i = 0; i < 3; ++i) {
            change[x][i] = -x + static_cast<int>(1LL * A[i] * x / B[i]);
        }
    }
 
    vector<long long> prev(T, 0), cur(T, 0);
 
    auto action_value = [&](int w, int x, long long scale_prev) {
        long long total = 0;
        for (int i = 0; i < 3; ++i) {
            int next = w + change[x][i];
            long long continuation = (next >= T) ? scale_prev : prev[next];
            total += 1LL * P[i] * continuation;
        }
        return total;
    };
 
    // Build optimal continuation values for 1, 2, ..., N-1 remaining wagers.
    for (int t = 1; t < N; ++t) {
        fill(cur.begin(), cur.end(), 0);
        long long scale_prev = pow100[t - 1];
 
        for (int w = 1; w < T; ++w) {
            long long best = 0;
            for (int x = 1; x <= w; ++x) {
                best = max(best, action_value(w, x, scale_prev));
            }
            cur[w] = best;
        }
 
        prev.swap(cur);
    }
 
    // Evaluate the first wager separately so every optimal first choice is reported.
    long long scale_prev = pow100[N - 1];
    long long best = -1;
    vector<int> optimal;
 
    for (int x = 1; x <= S; ++x) {
        long long value = action_value(S, x, scale_prev);
        if (value > best) {
            best = value;
            optimal.clear();
            optimal.push_back(x);
        } else if (value == best) {
            optimal.push_back(x);
        }
    }
 
    cout << best / pow100[N - 1] << '\n';
    cout << optimal.size() << '\n';
    for (size_t i = 0; i < optimal.size(); ++i) {
        if (i) cout << ' ';
        cout << optimal[i];
    }
    cout << '\n';
 
    return 0;
}
0