結果

問題 No.2291 Union Find Estimate
ユーザー KudeKude
提出日時 2023-05-05 21:55:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,863 bytes
コンパイル時間 2,711 ms
コンパイル使用メモリ 228,424 KB
実行使用メモリ 5,056 KB
最終ジャッジ日時 2023-08-15 03:55:21
合計ジャッジ時間 3,980 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  dsu d(n);
  VI val(n, -1);
  mint ans = mint(10).pow(n);
  const mint inv10 = mint(10).inv();

  auto set_val = [&](int i, int x) {
    i = d.leader(i);
    if (val[i] == -1) {
      val[i] = x;
      ans *= inv10;
    } else if (val[i] != x) {
      ans = 0;
    }
  };
  auto mrg = [&](int i, int j) {
    i = d.leader(i), j = d.leader(j);
    if (i != j) {
      int l = d.merge(i, j);
      if (val[i] == -1) {
        ans *= inv10;
        if (val[j] != -1) val[l] = val[j];
      } else if (val[j] == -1) {
        ans *= inv10;
        val[l] = val[i];
      } else if (val[i] != val[j]) {
        ans = 0;
      }
    }
  };

  while(q--) {
    string s;
    cin >> s;
    int idx[26];
    memset(idx, -1, sizeof(idx));
    rep(i, n) {
      if ('0' <= s[i] && s[i] <= '9') {
        set_val(i, s[i] - '0');
      } else if ('a' <= s[i] && s[i] <= 'z') {
        int x = s[i] - 'a';
        if (idx[x] == -1) idx[x] = i;
        else mrg(i, idx[x]);
      }
    }
    cout << ans.val() << '\n';
  }
}
0