結果
| 問題 |
No.2291 Union Find Estimate
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-14 16:34:29 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 291 ms / 2,000 ms |
| コード長 | 1,760 bytes |
| コンパイル時間 | 3,210 ms |
| コンパイル使用メモリ | 258,328 KB |
| 実行使用メモリ | 12,224 KB |
| 最終ジャッジ日時 | 2024-11-14 16:34:38 |
| 合計ジャッジ時間 | 4,616 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#ifndef LOCAL
#include <bits/stdc++.h>
using namespace std;
#define debug(...) (void(0))
#else
#include "algo/debug.h"
#endif
#include <atcoder/dsu>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
void solve() {
int W, H; cin >> W >> H;
atcoder::dsu uf(W);
vector<int> ans(W, -1);
bool Zero = false;
for(int i = 0; i < H; i++) {
array<int, 26> leader{};
for(int j = 0; j < 26; j++) leader[j] = -1;
string Q; cin >> Q;
for(unsigned j = 0; j < Q.size(); j++) if(Q[j] != '?') {
if(isdigit(Q[j])) {
if(ans[j] != -1 && ans[j] != Q[j] - '0') {
Zero = true;
}else {
ans[j] = Q[j] - '0';
}
}else {
int a = Q[j] - 'a';
if(leader[a] != -1) {
if(!uf.same(leader[a], j)) {
uf.merge(leader[a], j);
}
}else {
leader[a] = j;
}
}
}
auto grs = uf.groups();
int cc = 0;
for(auto&&gr: grs) {
int val = -1;
for(int v : gr) if(ans[v] != -1) {
if(val == -1) val = ans[v];
else if(val != ans[v])Zero = true;
}
if(val != -1) {
for(int v: gr) {
ans[v] = val;
}
}else {
cc++;
}
}
debug(ans);
cout << (Zero ? 0 : mint(10).pow(cc).val()) << endl;
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1;
// std::cin >> tt;
while(tt--) {
solve();
}
}