結果

問題 No.2291 Union Find Estimate
ユーザー 👑 tatyamtatyam
提出日時 2023-05-05 21:57:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 900 bytes
コンパイル時間 3,396 ms
コンパイル使用メモリ 255,628 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 03:58:29
合計ジャッジ時間 4,383 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 49 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>
#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint998244353;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    
    int N, Q;
    cin >> N >> Q;
    atcoder::dsu uf(N + 10);
    mint ans = mint{10}.pow(N);
    const mint inv10 = mint{10}.inv();

    auto merge = [&](int i, int j) {
        if(i == -1) return;
        if(uf.same(i, j)) return;
        uf.merge(i, j);
        ans *= inv10;
    };

    while(Q--) {
        string S;
        cin >> S;
        for(int i = 0; i < N; i++) if(isdigit(S[i])) merge(i, N + S[i] - 48);
        vector<int> prev(26, -1);
        for(int i = 0; i < N; i++) if(islower(S[i])) {
            merge(exchange(prev[S[i] - 'a'], i), i);
        }
        for(int i = 0; i < 10; i++) for(int j = 0; j < i; j++) if(uf.same(N + i, N + j)) ans = 0;
        cout << ans.val() << '\n';
    }
}
0