結果

問題 No.3851 Dreams
コンテスト
ユーザー Nzt3
提出日時 2026-11-06 16:39:38
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 462 ms / 2,000 ms
+ 806µs
コード長 2,296 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,699 ms
コンパイル使用メモリ 348,480 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-12-04 21:02:39
合計ジャッジ時間 9,802 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// GPT 6 Luna
#include <bits/stdc++.h>
#include <atcoder/modint.hpp>

using namespace std;
using ll = long long;
using mint = atcoder::modint998244353;

struct Skill {
    ll x, y, p, s;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<Skill> skills(n);
    for (auto& skill : skills) {
        cin >> skill.x >> skill.y >> skill.p >> skill.s;
    }
    sort(skills.begin(), skills.end(), [](const Skill& a, const Skill& b) {
        return a.s < b.s;
    });

    vector<ll> times(m);
    for (ll& t : times) cin >> t;

    const mint inv100 = mint(100).inv();
    mint answer = 0;

    for (ll t : times) {
        vector<mint> no_active(n);
        for (int i = 0; i < n; ++i) {
            const auto& skill = skills[i];
            ll count = t / skill.x;
            if (t >= skill.y) {
                count -= (t - skill.y) / skill.x;
            }
            mint no_success = mint(1) - mint(skill.p) * inv100;
            no_active[i] = no_success.pow(count);
        }

        // For each strength threshold s, compute the probability that no
        // active boost has strength at least s, then sum the expectation tail.
        vector<mint> no_boost_at_least(n);
        int right = n;
        mint suffix_no_active = 1;
        while (right > 0) {
            int left = right - 1;
            while (left > 0 && skills[left - 1].s == skills[right - 1].s) --left;
            for (int i = left; i < right; ++i) {
                suffix_no_active *= no_active[i];
            }
            for (int i = left; i < right; ++i) {
                no_boost_at_least[i] = suffix_no_active;
            }
            right = left;
        }

        ll previous_strength = 1;
        mint expected_score = 1;
        for (int left = 0; left < n;) {
            int right_group = left + 1;
            while (right_group < n && skills[right_group].s == skills[left].s) ++right_group;
            ll strength = skills[left].s;
            expected_score += mint(strength - previous_strength)
                            * (mint(1) - no_boost_at_least[left]);
            previous_strength = strength;
            left = right_group;
        }
        answer += expected_score;
    }

    cout << answer.val() << '\n';
}
0