結果

問題 No.2291 Union Find Estimate
ユーザー lgswdn
提出日時 2023-05-06 20:59:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 197,360 KB
最終ジャッジ日時 2025-02-12 20:37:55
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |     scanf("%s",s+1);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define popc __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef long double ld;

int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=2e5+9,mod=998244353;

int n,m,p[N],id[N],flag;
char s[N];
vi r[29];

int find(int x) {return x==id[x]?x:id[x]=find(id[x]);}
int merge(int x,int y) {
  x=find(x), y=find(y); id[y]=x;
  if(p[x]==-1) return p[x]=p[y], 1;
  else return p[y]==-1||p[x]==p[y];
}
int col(int x,int y) {
  x=find(x);
  if(p[x]==-1) return p[x]=y,1;
  else return p[x]==y;
}

signed main() {
  n=read(), m=read(); flag=1;
  rep(i,1,n) p[i]=-1, id[i]=i;
  rep(i,1,m) {
    scanf("%s",s+1);
    if(flag==0) {puts("0"); continue;}
    rep(i,0,25) r[i].clear();
    rep(j,1,n) if(isalpha(s[j])) r[s[j]-'a'].eb(j);
    rep(j,0,25) if(r[j].size()) {
      int x=find(r[j][0]), sz=r[j].size();
      rep(i,1,sz-1) flag&=merge(x,find(r[j][i]));
    }
    rep(j,1,n) if(isdigit(s[j])) flag&=col(find(j),s[j]-'0');
    int ans=flag;
    rep(j,1,n) if(find(j)==j) ans=(ans*(1+9*(p[j]==-1)))%mod;
    printf("%lld\n",ans);
  }
  return 0;
}
0