結果

問題 No.2291 Union Find Estimate
ユーザー 👑 kmjpkmjp
提出日時 2023-05-05 21:37:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 2,052 bytes
コンパイル時間 2,646 ms
コンパイル使用メモリ 212,672 KB
実行使用メモリ 19,900 KB
最終ジャッジ日時 2023-08-15 03:16:05
合計ジャッジ時間 4,762 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
16,396 KB
testcase_01 AC 8 ms
16,460 KB
testcase_02 AC 412 ms
16,320 KB
testcase_03 AC 23 ms
19,900 KB
testcase_04 AC 22 ms
16,684 KB
testcase_05 AC 23 ms
16,772 KB
testcase_06 AC 17 ms
16,520 KB
testcase_07 AC 12 ms
16,412 KB
testcase_08 AC 30 ms
16,796 KB
testcase_09 AC 33 ms
16,700 KB
testcase_10 AC 43 ms
17,168 KB
testcase_11 AC 62 ms
16,564 KB
testcase_12 AC 103 ms
16,476 KB
testcase_13 AC 67 ms
18,752 KB
testcase_14 AC 23 ms
16,844 KB
testcase_15 AC 23 ms
17,252 KB
testcase_16 AC 19 ms
16,796 KB
testcase_17 AC 46 ms
17,032 KB
testcase_18 AC 46 ms
17,016 KB
testcase_19 AC 42 ms
17,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int W,H;
string Q[202020];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt,G[um];
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit(int num=um) {int i; FOR(i,num) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
	void dump(int num=um) { //グループ分けした配列を作る
		int i;
		FOR(i,num) G[i].clear();
		FOR(i,num) G[operator[](i)].push_back(i);
	}
};
UF<202020> uf;
const ll mo=998244353;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>W>>H;
	FOR(y,H) {
		cin>>Q[y];
		vector<int> S[256];
		FOR(x,W) S[Q[y][x]].push_back(x);
		
		FOR(i,10) FORR(a,S['0'+i]) uf(a,200000+'0'+i);
		FOR(i,26) FORR(a,S['a'+i]) uf(a,S['a'+i][0]);
		ll ret=1;
		set<int> did;
		FOR(x,W) {
			i=0;
			FOR(j,10) if(uf[x]==uf[200000+j+'0']) i++;
			if(i==0) {
				if(did.count(uf[x])==0) ret=ret*10%mo, did.insert(uf[x]);
			}
			if(i>1) ret=0;
		}
		cout<<ret<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0