結果
問題 |
No.2291 Union Find Estimate
|
ユーザー |
|
提出日時 | 2023-05-12 17:53:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,458 bytes |
コンパイル時間 | 2,044 ms |
コンパイル使用メモリ | 197,780 KB |
最終ジャッジ日時 | 2025-02-12 21:39:41 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | AC * 18 |
ソースコード
#include<bits/stdc++.h> using namespace std; const int mod=998244353; constexpr int INPUT_MAX=200005; int rt[INPUT_MAX]; int getroot(int n){ if(rt[n]==-1)return n; return rt[n]=getroot(rt[n]); } void unite(int a,int b){ a=getroot(a),b=getroot(b); if(a!=b){ rt[a]=b; } } long long modpow(long long a,int n){ long long ret=1,t=a; for(int i=0;i<30;i++){ if(n>>i&1)ret=ret*t%mod; t=t*t%mod; } return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); fill(rt,rt+INPUT_MAX,-1); int W,H; cin>>W>>H; long long ans=modpow(10,W),inv10=modpow(10,mod-2); vector<int>SA(W,-1); for(int i=0;i<H;i++){ string S; cin>>S; array<int,26>l; for(int j=0;j<26;j++){ l[j]=-1; } for(int j=0;j<W;j++){ if(S[j]>='0'&&S[j]<='9'){ int rj=getroot(j); if(SA[rj]!=-1&&SA[rj]!=S[j]-'0'){ ans=0; } if(SA[rj]==-1){ ans=ans*inv10%mod; } SA[rj]=S[j]-'0'; }else if(S[j]!='?'){ if(l[S[j]-'a']!=-1){ int rl=getroot(l[S[j]-'a']),rj=getroot(j); if(rl!=rj){ if(SA[rl]!=-1&&SA[rj]!=-1&&SA[rl]!=SA[rj]){ ans=0; }else if(SA[rl]==-1){ SA[rl]=SA[rj]; }else{ SA[rj]=SA[rl]; } ans=ans*inv10%mod; } unite(rl,rj); } l[S[j]-'a']=j; } } cout<<ans<<'\n'; } }