提出 #36447762


ソースコード 拡げる

#include <bits/stdc++.h>
#include <atcoder/modint>

#ifdef PK
#include <debug.hpp>
#else
#define debug(...)
#endif
 
using namespace std;
 
#define all(a) (a).begin(), (a).end()
#define int long long

using mint = atcoder::modint998244353;
// using mint = double;

int32_t main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
 
    // E[visited blue], E[(visited blue)^2] for each
    // vertex after i stages
    // for every adjacent, 
    // if it is blue, add 1/deg * (1 + E[visited blue]) otherwise 1/deg * E[visited blue]
    // if it is blue, add 1/deg * (E[(visited blue)^2] + 2 * E[visited blue] + 1) otherwise 1/deg * E[(visited blue)^2]
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<int> c(n);
    for (auto &i: c) cin >> i;
    vector<mint> prob(n), dp(n), dp2(n);
    prob[0] = 1;
    mint res = 0;
    for (int mv = 0; mv < k; mv++) {
        vector<mint> nprob(n), ndp(n), ndp2(n);
        for (int at = 0; at < n; at++) {
            int deg = adj[at].size();
            auto lol = prob[at] / deg;
            for (auto&nxt: adj[at]) {
                nprob[nxt] += lol;
                ndp[nxt] += lol * ((1 - c[nxt]) + dp[at]);
                ndp2[nxt] += lol * (dp2[at] + (1 - c[nxt]) * (2 * dp[at] + 1));
            }
        }
        for (int nxt = 0; nxt < n; nxt++) {
            if (ndp[nxt].val() == 0 && ndp2[nxt].val() == 0)  
                continue;
            ndp[nxt] /= nprob[nxt];
            ndp2[nxt] /= nprob[nxt];
        }
        dp = ndp, dp2 = ndp2, prob = nprob;
        for (int i = 0; i < n; i++) {
            if (c[i]) res += dp2[i] * prob[i];
        }
    }
    cout << res.val() << '\n';
    // cout << res << '\n';
}

提出情報

提出日時
問題 G - Random Walk to Millionaire
ユーザ agtxdy
言語 C++ (GCC 9.2.1)
得点 600
コード長 1939 Byte
結果 AC
実行時間 2892 ms
メモリ 3940 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 2
AC × 35
セット名 テストケース
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, example0.txt, example1.txt
ケース名 結果 実行時間 メモリ
000.txt AC 8 ms 3612 KiB
001.txt AC 5 ms 3576 KiB
002.txt AC 4 ms 3592 KiB
003.txt AC 3 ms 3596 KiB
004.txt AC 4 ms 3688 KiB
005.txt AC 2 ms 3684 KiB
006.txt AC 1703 ms 3824 KiB
007.txt AC 1700 ms 3840 KiB
008.txt AC 1672 ms 3836 KiB
009.txt AC 1674 ms 3860 KiB
010.txt AC 1251 ms 3776 KiB
011.txt AC 1248 ms 3836 KiB
012.txt AC 1246 ms 3912 KiB
013.txt AC 2138 ms 3908 KiB
014.txt AC 2137 ms 3880 KiB
015.txt AC 237 ms 3692 KiB
016.txt AC 238 ms 3628 KiB
017.txt AC 2186 ms 3940 KiB
018.txt AC 2191 ms 3888 KiB
019.txt AC 110 ms 3644 KiB
020.txt AC 158 ms 3660 KiB
021.txt AC 1455 ms 3936 KiB
022.txt AC 1432 ms 3708 KiB
023.txt AC 1815 ms 3812 KiB
024.txt AC 353 ms 3612 KiB
025.txt AC 1362 ms 3832 KiB
026.txt AC 2892 ms 3780 KiB
027.txt AC 1557 ms 3800 KiB
028.txt AC 851 ms 3668 KiB
029.txt AC 1928 ms 3788 KiB
030.txt AC 1000 ms 3724 KiB
031.txt AC 1074 ms 3660 KiB
032.txt AC 917 ms 3700 KiB
example0.txt AC 2 ms 3620 KiB
example1.txt AC 2 ms 3588 KiB