結果

問題 No.2291 Union Find Estimate
ユーザー achapiachapi
提出日時 2023-05-05 22:38:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 1,093 bytes
コンパイル時間 5,486 ms
コンパイル使用メモリ 268,980 KB
実行使用メモリ 15,124 KB
最終ジャッジ日時 2023-08-15 05:24:49
合計ジャッジ時間 7,060 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 373 ms
4,376 KB
testcase_03 AC 81 ms
15,124 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 6 ms
4,388 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 9 ms
4,376 KB
testcase_09 AC 10 ms
4,376 KB
testcase_10 AC 34 ms
4,384 KB
testcase_11 AC 50 ms
4,380 KB
testcase_12 AC 86 ms
4,380 KB
testcase_13 AC 30 ms
6,036 KB
testcase_14 AC 33 ms
4,380 KB
testcase_15 AC 44 ms
7,688 KB
testcase_16 AC 36 ms
4,376 KB
testcase_17 AC 27 ms
4,380 KB
testcase_18 AC 27 ms
4,376 KB
testcase_19 AC 32 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using mint = atcoder::modint998244353;
using namespace std;

int main() {
	int w, h;
	cin >> w >> h;
	atcoder::dsu uf(w);
	vector<int> a(w, -1);
	bool ok = true;
	while (h--){
		string s;
		cin >> s;
		for (int i = 0; i < w; i++){
			if (isdigit(s[i])){
				if (a[i] != -1 and a[i] != (s[i] - '0')){
					ok = false;
					break;
				}
				a[i] = s[i] - '0';
			}
		}
		if (!ok){
			cout << 0 << endl;
			continue;
		}
		for (int k = 0; k < 26; k++){
			set<int> t;
			for (int i = 0; i < w; i++){
				if (s[i] == (char)('a' + k)){
					t.insert(i);
				}
			}
			vector<int> l(t.begin(), t.end());
			for (int i = 0; i < max(0, (int)l.size() - 1); i++){
				uf.merge(l[i], l[i + 1]);
			}
		}
		mint ans = 1;
		auto g = uf.groups();
		for (auto t : g){
			set<int> p;
			for (int i = 0; i < (int)t.size(); i++){
				if (a[t[i]] != -1){
					p.insert(a[t[i]]);
				}
			}
			if (p.size() > 1){
				ok = false;
			}
			if (p.size() == 0){
				ans *= 10;
			}
		}
		if (!ok){
			cout << 0 << endl;
			continue;
		}
		cout << ans.val() << endl;
	}
}
0