結果

問題 No.2291 Union Find Estimate
ユーザー kotatsugamekotatsugame
提出日時 2023-05-05 21:28:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 690 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 11,292 KB
最終ジャッジ日時 2023-08-15 02:58:36
合計ジャッジ時間 2,383 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 180 ms
4,380 KB
testcase_03 AC 11 ms
11,292 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 13 ms
4,384 KB
testcase_10 AC 17 ms
4,376 KB
testcase_11 AC 25 ms
4,380 KB
testcase_12 AC 43 ms
4,380 KB
testcase_13 AC 22 ms
5,940 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 11 ms
7,364 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 19 ms
4,380 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 16 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<atcoder/dsu>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,M;
	cin>>N>>M;
	atcoder::dsu uf(N+10);
	for(;M--;)
	{
		string Q;cin>>Q;
		vector<int>prv(26,-1);
		for(int i=0;i<N;i++)
		{
			if(Q[i]=='?');
			else if(Q[i]>='0'&&Q[i]<='9')
			{
				uf.merge(i,N+Q[i]-'0');
			}
			else
			{
				int c=Q[i]-'a';
				if(prv[c]!=-1)uf.merge(prv[c],i);
				prv[c]=i;
			}
		}
		int ans=1;
		const int mod=998244353;
		for(vector<int>g:uf.groups())
		{
			int ex=0;
			for(int v:g)if(v>=N)ex|=1<<v-N;
			if(ex)
			{
				if(__builtin_popcount(ex)>1)ans=0;
			}
			else
			{
				ans=ans*10LL%mod;
			}
		}
		cout<<ans<<"\n";
	}
}
0