結果
| 問題 |
No.2291 Union Find Estimate
|
| コンテスト | |
| ユーザー |
ぷら
|
| 提出日時 | 2023-05-05 21:31:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 2,270 bytes |
| コンパイル時間 | 2,361 ms |
| コンパイル使用メモリ | 209,856 KB |
| 最終ジャッジ日時 | 2025-02-12 17:35:51 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> par;
vector<int> size;
UnionFind(int n) {
par.resize(n);
size.resize(n,1);
for(int i = 0; i < n; i++) {
par[i] = i;
}
}
int find(int x) {
if(par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
bool same(int x, int y) {
return find(x) == find(y);
}
int consize(int x) {
return size[find(x)];
}
bool unite(int x, int y) {
x = find(x);
y = find(y);
if(x == y) {
return false;
}
if(size[x] > size[y]) {
swap(x,y);
}
par[x] = y;
size[y] += size[x];
return true;
}
};
constexpr int mod = 998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int W,H;
cin >> W >> H;
vector<int>tmp(W,-1);
UnionFind uf(W);
bool f = true;
for(int i = 0; i < H; i++) {
string Q;
cin >> Q;
vector<vector<int>>id(26);
for(int j = 0; j < W; j++) {
if(Q[j] == '?') continue;
if(Q[j] >= '0' && Q[j] <= '9') {
int c = Q[j]-'0';
if(tmp[j] == -1) tmp[j] = c;
else if(tmp[j] != c) f = false;
}
else {
id[Q[j]-'a'].push_back(j);
}
}
for(int j = 0; j < 26; j++) {
for(int k = 1; k < id[j].size(); k++) {
uf.unite(id[j][k-1],id[j][k]);
}
}
map<int,int>mp;
for(int j = 0; j < W; j++) {
int c = uf.find(j);
int d = tmp[j];
if(!mp.count(c)) {
mp[c] = d;
}
else {
if(mp[c] == -1) {
mp[c] = d;
}
else if(d != -1 && mp[c] != d) {
f = false;
}
}
}
if(!f) {
cout << 0 << "\n";
continue;
}
int ans = 1;
for(auto j:mp) {
if(j.second == -1) {
ans = 10ll*ans%mod;
}
}
cout << ans << "\n";
}
}
ぷら