結果

問題 No.2291 Union Find Estimate
ユーザー SSRS
提出日時 2023-05-05 21:33:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,409 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 173,340 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-11-23 06:15:10
合計ジャッジ時間 3,083 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long ONE_TENTH = 299473306;
struct unionfind{
vector<int> p;
long long ans;
vector<int> s;
unionfind(int N): p(N, -1), ans(1), s(N, -1){
for (int i = 0; i < N; i++){
ans *= 10;
ans %= MOD;
}
}
int root(int x){
if (p[x] == -1){
return x;
} else {
p[x] = root(p[x]);
return p[x];
}
}
void set(int x, int y){
x = root(x);
if (s[x] == -1){
s[x] = y;
ans *= ONE_TENTH;
ans %= MOD;
} else if (s[x] != y){
ans = 0;
}
}
void unite(int x, int y){
x = root(x);
y = root(y);
if (x != y){
p[x] = y;
if (s[x] == -1 || s[y] == -1){
ans *= ONE_TENTH;
ans %= MOD;
if (s[y] == -1){
s[y] = s[x];
}
} else if (s[x] != s[y]){
ans = 0;
}
}
}
};
int main(){
int W, H;
cin >> W >> H;
vector<string> Q(H);
for (int i = 0; i < H; i++){
cin >> Q[i];
}
unionfind UF(W);
for (int i = 0; i < H; i++){
vector<int> p(26, -1);
for (int j = 0; j < W; j++){
if (isdigit(Q[i][j]) > 0){
UF.set(j, Q[i][j] - '0');
} else if (isalpha(Q[i][j]) > 0){
int c = Q[i][j] - 'a';
if (p[c] != -1){
UF.unite(p[c], j);
}
p[c] = j;
}
}
cout << UF.ans << endl;
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0