結果

問題 No.3053 $((0 \And 1)\mathop{|}2)\oplus 3$
ユーザー rin204
提出日時 2025-02-05 20:15:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 897 bytes
コンパイル時間 9,943 ms
コンパイル使用メモリ 354,400 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2025-03-08 00:10:54
合計ジャッジ時間 11,623 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include "atcoder/modint.hpp"
using mint = atcoder::modint998244353;

#include "testlib.h"

void solve() {
    std::string S = inf.readToken(format("[01]{%d, %d}", 1, 1'000'000));
    inf.readEoln();
    ensure(S[0] == '1');
    std::reverse(S.begin(), S.end());
    int n = S.size();

    mint three = 3;
    mint c0    = mint(2) / 3;
    mint all_  = c0;
    auto t     = c0;
    mint two   = 1;
    mint ans   = 0;
    for (int i = 0; i < n; i++) {
        if (S[i] == '1') {
            ans += two;
            all_ *= three;
            t *= c0;
        } else {
            ans += two * t;
        }
        three *= three;
        two *= 2;
        c0 *= c0;
    }
    std::cout << (ans * all_).val() << std::endl;
}

int main(int argc, char *argv[]) {
    std::cin.tie(0)->sync_with_stdio(0);
    registerValidation(argc, argv);
    solve();
    inf.readEof();
}
0