QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22963 | #2892. 合法序列 | WhybullYMe# | AC ✓ | 6ms | 3880kb | C++20 | 2.5kb | 2022-03-11 12:30:11 | 2022-04-30 02:11:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ri int
typedef long long ll;
const int maxn=510,mod=998244353;
template<class T>inline bool ckmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T>inline bool ckmax(T &x,const T &y){return x<y?x=y,1:0;}
template<class T>inline void clear(T *arr,int siz,int val=0){memset(arr,val,sizeof(T)*(siz+1));}
struct modint{
int val;
inline modint(int val_=0):val(val_){}
inline modint &operator=(int val_){return val=val_,*this;}
inline modint &operator+=(const modint &k){return val=val+k.val>=mod?val+k.val-mod:val+k.val,*this;}
inline modint &operator-=(const modint &k){return val=val-k.val<0?val-k.val+mod:val-k.val,*this;}
inline modint &operator*=(const modint &k){return val=1ll*val*k.val%mod,*this;}
inline modint &operator^=(int k){
modint ret=1,tmp=*this;
for(;k;k>>=1,tmp*=tmp)if(k&1)ret*=tmp;
return val=ret.val,*this;
}
inline modint &operator/=(modint k){return *this*=(k^=mod-2);}
inline modint &operator+=(int k){return val=val+k>=mod?val+k-mod:val+k,*this;}
inline modint &operator-=(int k){return val=val<k?val-k+mod:val-k,*this;}
inline modint &operator*=(int k){return val=1ll*val*k%mod,*this;}
inline modint &operator/=(int k){return *this*=((modint(k))^=mod-2);}
template<class T>friend modint operator+(modint a,T b){return a+=b;}
template<class T>friend modint operator-(modint a,T b){return a-=b;}
template<class T>friend modint operator*(modint a,T b){return a*=b;}
template<class T>friend modint operator^(modint a,T b){return a/=b;}
template<class T>friend modint operator/(modint a,T b){return a/=b;}
friend modint operator^(modint a,int b){return a^=b;}
friend bool operator==(modint a,int b){return a.val==b;}
friend bool operator!=(modint a,int b){return a.val!=b;}
inline bool operator!(){return !val;}
inline modint operator-(){return val?mod-val:0;}
inline modint &operator++(){return *this+=1;}
};
using mi=modint;
mi ans,f[1<<4][maxn];
int lim[1<<4],k,n;
int main(){
scanf("%d%d",&n,&k);
for(ri i=0;i<1<<k;++i)
for(ri j=0;j<k;++j)
if(i&(1<<j))
lim[i]|=1<<k-j-1;
for(ri i=0;i<1<<(1<<k);++i){
for(ri j=0;j<=(1<<k)-k;++j)
if(!(i&(1<<lim[(i>>j)&((1<<k)-1)])))
goto skip;
memset(f,0,sizeof f);
f[i>>((1<<k)-k)][(1<<k)-1]=1;
for(ri l=1<<k;l<n;++l)
for(ri j=0;j<1<<k;++j){
if(!(i&(1<<lim[j])))continue;
ri pre=(j&~(1<<k-1))<<1;
f[j][l]=f[pre][l-1]+f[pre|1][l-1];
}
for(ri j=0;j<1<<k;++j)ans+=f[j][n-1];
skip:;
}
printf("%d",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3808kb
input:
2 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3720kb
input:
10 3
output:
27
result:
ok single line: '27'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3792kb
input:
11 3
output:
46
result:
ok single line: '46'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
500 3
output:
402086823
result:
ok single line: '402086823'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3792kb
input:
16 4
output:
268
result:
ok single line: '268'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3840kb
input:
17 4
output:
520
result:
ok single line: '520'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
18 4
output:
939
result:
ok single line: '939'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
19 4
output:
1634
result:
ok single line: '1634'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
20 4
output:
2678
result:
ok single line: '2678'
Test #10:
score: 0
Accepted
time: 3ms
memory: 3792kb
input:
500 4
output:
905810545
result:
ok single line: '905810545'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
156 3
output:
158348364
result:
ok single line: '158348364'
Test #12:
score: 0
Accepted
time: 3ms
memory: 3812kb
input:
3 1
output:
2
result:
ok single line: '2'
Test #13:
score: 0
Accepted
time: 3ms
memory: 3812kb
input:
419 1
output:
309520444
result:
ok single line: '309520444'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3820kb
input:
148 1
output:
981388471
result:
ok single line: '981388471'
Test #15:
score: 0
Accepted
time: 3ms
memory: 3740kb
input:
208 1
output:
17788609
result:
ok single line: '17788609'
Test #16:
score: 0
Accepted
time: 3ms
memory: 3804kb
input:
325 4
output:
534470501
result:
ok single line: '534470501'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
478 1
output:
275981743
result:
ok single line: '275981743'
Test #18:
score: 0
Accepted
time: 3ms
memory: 3764kb
input:
437 3
output:
448979837
result:
ok single line: '448979837'
Test #19:
score: 0
Accepted
time: 5ms
memory: 3876kb
input:
260 3
output:
249722589
result:
ok single line: '249722589'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
406 2
output:
762498912
result:
ok single line: '762498912'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
348 2
output:
718553190
result:
ok single line: '718553190'
Test #22:
score: 0
Accepted
time: 3ms
memory: 3820kb
input:
350 1
output:
496751081
result:
ok single line: '496751081'
Test #23:
score: 0
Accepted
time: 2ms
memory: 3812kb
input:
500 1
output:
154029661
result:
ok single line: '154029661'
Test #24:
score: 0
Accepted
time: 6ms
memory: 3812kb
input:
344 4
output:
864324256
result:
ok single line: '864324256'
Test #25:
score: 0
Accepted
time: 3ms
memory: 3716kb
input:
127 3
output:
306783420
result:
ok single line: '306783420'
Test #26:
score: 0
Accepted
time: 4ms
memory: 3808kb
input:
170 4
output:
138463737
result:
ok single line: '138463737'
Test #27:
score: 0
Accepted
time: 3ms
memory: 3804kb
input:
199 3
output:
988988696
result:
ok single line: '988988696'
Test #28:
score: 0
Accepted
time: 3ms
memory: 3788kb
input:
206 3
output:
992080398
result:
ok single line: '992080398'
Test #29:
score: 0
Accepted
time: 3ms
memory: 3808kb
input:
82 2
output:
755922348
result:
ok single line: '755922348'
Test #30:
score: 0
Accepted
time: 3ms
memory: 3788kb
input:
351 2
output:
285073312
result:
ok single line: '285073312'
Test #31:
score: 0
Accepted
time: 3ms
memory: 3812kb
input:
274 1
output:
609866862
result:
ok single line: '609866862'
Test #32:
score: 0
Accepted
time: 2ms
memory: 3796kb
input:
416 3
output:
49398792
result:
ok single line: '49398792'
Test #33:
score: 0
Accepted
time: 3ms
memory: 3816kb
input:
4 2
output:
2
result:
ok single line: '2'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
5 2
output:
4
result:
ok single line: '4'
Test #35:
score: 0
Accepted
time: 3ms
memory: 3788kb
input:
6 2
output:
7
result:
ok single line: '7'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
500 2
output:
255888452
result:
ok single line: '255888452'
Test #37:
score: 0
Accepted
time: 3ms
memory: 3808kb
input:
8 3
output:
8
result:
ok single line: '8'
Test #38:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
9 3
output:
15
result:
ok single line: '15'