結果

問題 No.1840 Random Painting
ユーザー 👑 hitonanodehitonanode
提出日時 2021-12-12 23:52:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,721 bytes
コンパイル時間 1,313 ms
コンパイル使用メモリ 113,764 KB
実行使用メモリ 16,640 KB
最終ジャッジ日時 2023-09-09 23:30:59
合計ジャッジ時間 12,873 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,772 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 15 ms
4,384 KB
testcase_08 AC 11 ms
4,384 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
using namespace std;

#include <atcoder/modint>
#include <atcoder/math>
using mint1 = atcoder::modint998244353;
using mint2 = atcoder::modint998244353;

template <class Mint> Mint A107984(Mint n, Mint k) { return (k + 1) * (n + 2) * (2 * n - k + 3) * (n - k + 1) / 6; }

// 右に r ステップ進むより左に l ステップ進む方が先の確率 * (そのようなときにそれを達成するまでの時間の条件付き期待値)
template <class Mint> Mint solve(int l, int r) {
    int N = l + r;
    return A107984<Mint>(N - 2, l - 1) * 2 / Mint(N * N);
}

template <class Mint> Mint sol(const string &S) {
    const int N = S.size();
    vector<int> zeropos;
    for (int i = 0; i < N; i++) {
        if (S[i] == '1') continue;
        zeropos.push_back(i);
    }
    mint1 ret = 0;

    for (int t = 0; t < 2; ++t) {
        ret += solve<mint1>(N - zeropos[0], zeropos[0]);
        for (auto &x : zeropos) x = N - x;
        reverse(zeropos.begin(), zeropos.end());
    }

    for (int i = 1; i < int(zeropos.size()); ++i) {
        int a = zeropos[i - 1], b = zeropos[i];
        for (int t = 0; t < 2; ++t) {
            auto e1 = solve<mint1>(a, N - b);
            auto e2 = solve<mint1>(N - (b - a), b - a);
            ret += e1 * (b - a) / N + e2 * (N - b) / (N - b + a);
            swap(a, b);
            a = N - a;
            b = N - b;
        }
    }
    return ret;
}

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    auto v1 = sol<mint1>(S).val();
    auto v2 = sol<mint2>(S).val();
    cout << atcoder::crt({v1, v2}, {mint1::mod(), mint2::mod()}).first << '\n';
}

0