結果

問題 No.2291 Union Find Estimate
ユーザー Ecrade_Ecrade_
提出日時 2023-05-05 21:39:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,878 bytes
コンパイル時間 1,881 ms
コンパイル使用メモリ 172,504 KB
実行使用メモリ 13,924 KB
最終ジャッジ日時 2024-05-02 15:37:06
合計ジャッジ時間 3,696 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 319 ms
5,376 KB
testcase_03 AC 17 ms
13,924 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 7 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 24 ms
5,376 KB
testcase_11 AC 39 ms
5,376 KB
testcase_12 AC 70 ms
5,376 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 13 ms
7,680 KB
testcase_16 AC 9 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 9 ms
5,376 KB
testcase_19 AC 25 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
ll t = 1,n,m,k,q,l,r,b,c,u,v,x,y,z,id[200009],a[200009],nm[200009],vis[200009];
string s;
vector <ll> to[29];
struct st{ll x,y; /*bool operator < (const st &a) const{return x < a.x;};*/};
bool cmp(const st &a,const st &b){return a.x < b.x;}
inline ll read(){
	ll s = 0,w = 1;
	char ch = getchar();
	while (ch > '9' || ch < '0'){ if (ch == '-') w = -1; ch = getchar();}
	while (ch <= '9' && ch >= '0') s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar();
	return s * w;
}
ll qp(ll x,ll y){
	ll a = 1,b = x;
	while (y){
		if (y & 1) a = a * b % mod;
		b = b * b % mod,y >>= 1;
	}
	return a;
}
ll find(ll x){return x == id[x] ? x : id[x] = find(id[x]);}
int main(){//t = read();
	n = read(),t = read();
	for (ll i = 1;i <= n;i += 1) a[i] = -1,id[i] = i;
	bool fl = 1;
	while (t --){
		cin>>s,s = ' ' + s;
		if (!fl){puts("0"); continue;}
		for (ll i = 0;i < 26;i += 1) to[i].clear();
		for (ll i = 1;i <= n;i += 1) nm[i] = -1;
		ll ans = 1;
		for (ll i = 1;i <= n;i += 1){
			if (s[i] == '?') continue;
			if (s[i] <= '9' && s[i] >= '0'){
				if (a[i] != -1 && a[i] != s[i] - '0'){fl = 0; break;}
				a[i] = s[i] - '0';
			}
			else to[s[i] - 'a'].emplace_back(i);
		}
		if (!fl){puts("0"); continue;}
		for (ll i = 0;i < 26;i += 1){
			for (ll j = 0;j + 1 < to[i].size();j += 1) id[find(to[i][j])] = find(to[i][j + 1]);
		}
		for (ll i = 1;i <= n;i += 1) if (a[i] != -1) nm[find(i)] = a[i];
		for (ll i = 1;i <= n;i += 1){
			ll qwq = find(i);
			if (a[i] == -1) continue;
			if (nm[qwq] != -1 && nm[qwq] != a[i]){fl = 0; break;}
			nm[qwq] = a[i];
		}
		if (!fl){puts("0"); continue;}
		for (ll i = 1;i <= n;i += 1) vis[i] = 0;
		ans = 1;
		for (ll i = 1;i <= n;i += 1) if (!vis[find(i)] && nm[find(i)] == -1) ans = ans * 10 % mod,nm[find(i)] = 1;
		printf("%lld\n",ans);
	}
	return 0;
}
0