結果

問題 No.2291 Union Find Estimate
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-04-09 11:37:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,808 bytes
コンパイル時間 7,860 ms
コンパイル使用メモリ 208,264 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 11:40:03
合計ジャッジ時間 11,930 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/dsu>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = atcoder::modint998244353;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    int h, w;
    cin >> h >> w;
    mint ans = mint(10).pow(h);
    mint inv_10 = mint(10).inv();
    dsu uf(h);
    string pw(h, '.');
    for (int i = 0; i < w; i++) {
        string s;
        cin >> s;
        vector<vector<int>> idx(26);
        for (int j = 0; j < h; j++) {
            if (s[j] == '?') {
                continue;
            } else if ('0' <= s[j] && s[j] <= '9') {
                if (pw[uf.leader(j)] == '.') {
                    pw[uf.leader(j)] = s[j];
                    ans *= inv_10;
                } else if (pw[uf.leader(j)] != s[j]) {
                    ans = 0;
                }
            } else {
                idx[s[j] - 'a'].push_back(j);
            }
        }

        for (int j = 0; j < 26; j++) {
            for (int k = 0; k + 1 < idx[j].size(); k++) {
                int u = uf.leader(idx[j][k]), v = uf.leader(idx[j][k + 1]);
                if (uf.same(u, v)) {
                    continue;
                }
                if (pw[u] == '.' && pw[v] == '.') {
                    uf.merge(u, v);
                    ans *= inv_10;
                } else if (pw[u] == '.') {
                    pw[u] = pw[v];
                    ans *= inv_10;
                } else if (pw[v] == '.') {
                    pw[v] = pw[u];
                    ans *= inv_10;
                } else if (pw[u] != pw[v]) {
                    ans = 0;
                } else {
                    uf.merge(u, v);
                }
            }
        }

        cout << ans.val() << "\n";
    }
}
0