結果
問題 | No.2291 Union Find Estimate |
ユーザー | Ecrade_ |
提出日時 | 2023-05-05 21:38:25 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,872 bytes |
コンパイル時間 | 1,734 ms |
コンパイル使用メモリ | 172,564 KB |
実行使用メモリ | 14,060 KB |
最終ジャッジ日時 | 2024-11-23 06:27:41 |
合計ジャッジ時間 | 3,303 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 322 ms
5,248 KB |
testcase_03 | AC | 16 ms
14,060 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 7 ms
5,248 KB |
testcase_10 | AC | 25 ms
5,248 KB |
testcase_11 | AC | 40 ms
5,248 KB |
testcase_12 | AC | 71 ms
5,248 KB |
testcase_13 | AC | 10 ms
5,248 KB |
testcase_14 | AC | 9 ms
5,248 KB |
testcase_15 | AC | 12 ms
7,808 KB |
testcase_16 | AC | 8 ms
5,248 KB |
testcase_17 | AC | 8 ms
5,248 KB |
testcase_18 | AC | 9 ms
5,248 KB |
testcase_19 | AC | 23 ms
5,248 KB |
ソースコード
#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[i] != -1 && nm[i] != a[i]){fl = 0; break;} nm[i] = 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; }