Submission #67004314
Source Code Expand
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define bi __int128_t
#define lb(x) ((x)&(-(x)))
#define gp(i,j) (((i)>>(j-1))&1)
#define ppc __builtin_popcount
#define ctz __builtin_ctz
#define db long double
using namespace std;
const int N=5e5+10,mod=998244353,inf=1e9+10;
const db eps=1e-8;
bool Mbg;
void Add(int &a,int b){a+=b;if(a>=mod) a-=mod;}
void Sub(int &a,int b){a-=b;if(a<0) a+=mod;}
void Mul(int &a,int b){a=1ll*a*b%mod;}
int qp(int a,int b){
int x=1;
while(b){
if(b&1) Mul(x,a);
Mul(a,a);b>>=1;
}return x;
}
int p2[N];
struct Trie{
int T[N][2];int tot=1;
int f[N],g[N],c[N];
void init(){g[0]=1;}
void upd(string s){
vector<int> pos;
int now=1;pos.push_back(now);
for(auto ch:s){
int o=ch-'A';
if(!T[now][o]) T[now][o]=++tot;
now=T[now][o];
pos.push_back(now);
}reverse(pos.begin(),pos.end());
c[now]++;
for(auto ed:pos){
f[ed]=1ll*f[T[ed][0]]*f[T[ed][1]]%mod;
g[ed]=1ll*g[T[ed][0]]*g[T[ed][1]]%mod;
//cout<<ed<<' '<<T[ed][0]<<' '<<f[ed]<<' '<<g[ed]<<endl;
int w=(g[ed]+mod-f[ed])%mod;
Mul(g[ed],p2[c[ed]]);
f[ed]=(g[ed]+mod-w)%mod;
}
}
}T;
int n;
string st[N];
void slv(){
cin>>n;
for(int i=1;i<=n;i++) cin>>st[i];
p2[0]=1;
for(int i=1;i<=n;i++) p2[i]=2ll*p2[i-1]%mod;
T.init();
for(int i=1;i<=n;i++){
T.upd(st[i]);
cout<<T.f[1]<<endl;
}
}
bool Med;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;//cin>>t;
while(t--) slv();
cout.flush();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<' '<<(&Mbg-&Med)/1024.0/1024.0<<endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Prefix Covering |
| User | LYLAKIOIAKIOI |
| Language | C++ 20 (gcc 12.2) |
| Score | 600 |
| Code Size | 1961 Byte |
| Status | AC |
| Exec Time | 58 ms |
| Memory | 29676 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample-01.txt, sample-02.txt |
| All | 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 04-01.txt, 04-02.txt, 04-03.txt, 04-04.txt, 05-01.txt, 05-02.txt, 05-03.txt, 05-04.txt, 05-05.txt, 05-06.txt, 05-07.txt, 05-08.txt, 06-01.txt, 06-02.txt, 06-03.txt, 06-04.txt, 06-05.txt, 06-06.txt, 06-07.txt, 06-08.txt, 07-01.txt, 07-02.txt, 07-03.txt, 07-04.txt, 07-05.txt, 08-01.txt, 08-02.txt, 08-03.txt, 08-04.txt, 09-01.txt, 09-02.txt, 09-03.txt, 09-04.txt, sample-01.txt, sample-02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 02-01.txt | AC | 9 ms | 19572 KiB |
| 02-02.txt | AC | 9 ms | 19396 KiB |
| 02-03.txt | AC | 9 ms | 19384 KiB |
| 02-04.txt | AC | 8 ms | 19392 KiB |
| 02-05.txt | AC | 9 ms | 19460 KiB |
| 02-06.txt | AC | 8 ms | 19464 KiB |
| 02-07.txt | AC | 9 ms | 19460 KiB |
| 02-08.txt | AC | 9 ms | 19464 KiB |
| 02-09.txt | AC | 10 ms | 19472 KiB |
| 02-10.txt | AC | 11 ms | 19536 KiB |
| 02-11.txt | AC | 14 ms | 19456 KiB |
| 02-12.txt | AC | 19 ms | 19624 KiB |
| 02-13.txt | AC | 30 ms | 19856 KiB |
| 02-14.txt | AC | 51 ms | 20252 KiB |
| 03-01.txt | AC | 11 ms | 19312 KiB |
| 03-02.txt | AC | 14 ms | 19572 KiB |
| 03-03.txt | AC | 20 ms | 19676 KiB |
| 03-04.txt | AC | 30 ms | 19848 KiB |
| 03-05.txt | AC | 51 ms | 20268 KiB |
| 04-01.txt | AC | 22 ms | 29676 KiB |
| 04-02.txt | AC | 22 ms | 29608 KiB |
| 04-03.txt | AC | 21 ms | 28152 KiB |
| 04-04.txt | AC | 22 ms | 28136 KiB |
| 05-01.txt | AC | 58 ms | 20980 KiB |
| 05-02.txt | AC | 58 ms | 21360 KiB |
| 05-03.txt | AC | 57 ms | 21680 KiB |
| 05-04.txt | AC | 57 ms | 21948 KiB |
| 05-05.txt | AC | 56 ms | 22128 KiB |
| 05-06.txt | AC | 42 ms | 25980 KiB |
| 05-07.txt | AC | 33 ms | 27684 KiB |
| 05-08.txt | AC | 24 ms | 29420 KiB |
| 06-01.txt | AC | 57 ms | 20988 KiB |
| 06-02.txt | AC | 58 ms | 21468 KiB |
| 06-03.txt | AC | 57 ms | 21680 KiB |
| 06-04.txt | AC | 58 ms | 21848 KiB |
| 06-05.txt | AC | 56 ms | 22000 KiB |
| 06-06.txt | AC | 43 ms | 25852 KiB |
| 06-07.txt | AC | 33 ms | 27676 KiB |
| 06-08.txt | AC | 24 ms | 29432 KiB |
| 07-01.txt | AC | 49 ms | 21604 KiB |
| 07-02.txt | AC | 48 ms | 21572 KiB |
| 07-03.txt | AC | 46 ms | 21540 KiB |
| 07-04.txt | AC | 47 ms | 21524 KiB |
| 07-05.txt | AC | 48 ms | 21480 KiB |
| 08-01.txt | AC | 49 ms | 21540 KiB |
| 08-02.txt | AC | 48 ms | 21440 KiB |
| 08-03.txt | AC | 50 ms | 21312 KiB |
| 08-04.txt | AC | 50 ms | 21368 KiB |
| 09-01.txt | AC | 49 ms | 21572 KiB |
| 09-02.txt | AC | 50 ms | 21524 KiB |
| 09-03.txt | AC | 50 ms | 21344 KiB |
| 09-04.txt | AC | 50 ms | 21460 KiB |
| sample-01.txt | AC | 9 ms | 19564 KiB |
| sample-02.txt | AC | 9 ms | 19324 KiB |