QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#83430#2892. 合法序列ZBSTChen#AC ✓41ms5020kbC++141.1kb2023-03-01 21:21:042023-03-01 21:21:07

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-01 21:21:07]
  • 评测
  • 测评结果:AC
  • 用时:41ms
  • 内存:5020kb
  • [2023-03-01 21:21:04]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
inline int read(){
	int x=0,f=1;
	char ac=getchar();
	while(ac<'0'||ac>'9'){
		if(ac=='-') f=-1;
		ac=getchar();
	}
	while(ac>='0'&&ac<='9'){
		x=(x<<3)+(x<<1)+(ac-'0');
		ac=getchar();
	}
	return x*f;
}
int n,m,k,a[505];
const int mod=998244353;
long long ans,dp[505][505];
bool check(int x){
	int num=0;
	for(int i=x;i>=x-k+1;i--){
		num|=a[i]*(1<<(x-i));
	}
	return (a[num]!=0);
}
long long work(int x){
	std::vector<int> v;
	for(int i=0;i<m;i++) a[i]=0;
	for(int i=0;i<m;i++){
		if(x&(1<<i)){
			v.push_back(m-i-1);	
			a[m-i-1]=1;
		}
	}
	for(int i=k-1;i<m;i++){
		if(!check(i)) return 0;
	}
	int len=v.size();
	memset(dp,0,sizeof(dp));
	dp[m-1][x&((1<<k)-1)]=1;
	for(int i=m;i<n;i++){
		for(int j=0;j<len;j++){
			dp[i][v[j]]+=dp[i-1][(v[j]>>1)|(1<<k-1)]+dp[i-1][v[j]>>1];
			dp[i][v[j]]%=mod;
		}
	}
	long long sum=0;
	for(int i=0;i<len;i++){
		sum+=dp[n-1][v[i]];
		sum%=mod;
	}
	return sum;
}
int main(){
	n=read(),k=read();
	m=1<<k;
	for(int i=0;i<(1<<m);i++){
		ans+=work(i);
		ans%=mod;
	}
	printf("%lld",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4864kb

input:

2 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 1ms
memory: 4880kb

input:

10 3

output:

27

result:

ok single line: '27'

Test #3:

score: 0
Accepted
time: 3ms
memory: 5016kb

input:

11 3

output:

46

result:

ok single line: '46'

Test #4:

score: 0
Accepted
time: 3ms
memory: 4880kb

input:

500 3

output:

402086823

result:

ok single line: '402086823'

Test #5:

score: 0
Accepted
time: 41ms
memory: 4876kb

input:

16 4

output:

268

result:

ok single line: '268'

Test #6:

score: 0
Accepted
time: 37ms
memory: 4864kb

input:

17 4

output:

520

result:

ok single line: '520'

Test #7:

score: 0
Accepted
time: 31ms
memory: 4884kb

input:

18 4

output:

939

result:

ok single line: '939'

Test #8:

score: 0
Accepted
time: 34ms
memory: 4892kb

input:

19 4

output:

1634

result:

ok single line: '1634'

Test #9:

score: 0
Accepted
time: 30ms
memory: 4952kb

input:

20 4

output:

2678

result:

ok single line: '2678'

Test #10:

score: 0
Accepted
time: 28ms
memory: 4952kb

input:

500 4

output:

905810545

result:

ok single line: '905810545'

Test #11:

score: 0
Accepted
time: 3ms
memory: 4884kb

input:

156 3

output:

158348364

result:

ok single line: '158348364'

Test #12:

score: 0
Accepted
time: 3ms
memory: 4884kb

input:

3 1

output:

2

result:

ok single line: '2'

Test #13:

score: 0
Accepted
time: 3ms
memory: 4888kb

input:

419 1

output:

309520444

result:

ok single line: '309520444'

Test #14:

score: 0
Accepted
time: 3ms
memory: 4948kb

input:

148 1

output:

981388471

result:

ok single line: '981388471'

Test #15:

score: 0
Accepted
time: 3ms
memory: 4856kb

input:

208 1

output:

17788609

result:

ok single line: '17788609'

Test #16:

score: 0
Accepted
time: 27ms
memory: 4888kb

input:

325 4

output:

534470501

result:

ok single line: '534470501'

Test #17:

score: 0
Accepted
time: 3ms
memory: 4936kb

input:

478 1

output:

275981743

result:

ok single line: '275981743'

Test #18:

score: 0
Accepted
time: 3ms
memory: 4936kb

input:

437 3

output:

448979837

result:

ok single line: '448979837'

Test #19:

score: 0
Accepted
time: 1ms
memory: 4812kb

input:

260 3

output:

249722589

result:

ok single line: '249722589'

Test #20:

score: 0
Accepted
time: 1ms
memory: 4948kb

input:

406 2

output:

762498912

result:

ok single line: '762498912'

Test #21:

score: 0
Accepted
time: 1ms
memory: 4916kb

input:

348 2

output:

718553190

result:

ok single line: '718553190'

Test #22:

score: 0
Accepted
time: 3ms
memory: 4876kb

input:

350 1

output:

496751081

result:

ok single line: '496751081'

Test #23:

score: 0
Accepted
time: 3ms
memory: 4872kb

input:

500 1

output:

154029661

result:

ok single line: '154029661'

Test #24:

score: 0
Accepted
time: 32ms
memory: 4880kb

input:

344 4

output:

864324256

result:

ok single line: '864324256'

Test #25:

score: 0
Accepted
time: 3ms
memory: 4888kb

input:

127 3

output:

306783420

result:

ok single line: '306783420'

Test #26:

score: 0
Accepted
time: 30ms
memory: 4952kb

input:

170 4

output:

138463737

result:

ok single line: '138463737'

Test #27:

score: 0
Accepted
time: 3ms
memory: 4884kb

input:

199 3

output:

988988696

result:

ok single line: '988988696'

Test #28:

score: 0
Accepted
time: 3ms
memory: 5020kb

input:

206 3

output:

992080398

result:

ok single line: '992080398'

Test #29:

score: 0
Accepted
time: 3ms
memory: 4848kb

input:

82 2

output:

755922348

result:

ok single line: '755922348'

Test #30:

score: 0
Accepted
time: 0ms
memory: 4888kb

input:

351 2

output:

285073312

result:

ok single line: '285073312'

Test #31:

score: 0
Accepted
time: 1ms
memory: 4884kb

input:

274 1

output:

609866862

result:

ok single line: '609866862'

Test #32:

score: 0
Accepted
time: 3ms
memory: 4872kb

input:

416 3

output:

49398792

result:

ok single line: '49398792'

Test #33:

score: 0
Accepted
time: 3ms
memory: 4820kb

input:

4 2

output:

2

result:

ok single line: '2'

Test #34:

score: 0
Accepted
time: 2ms
memory: 4884kb

input:

5 2

output:

4

result:

ok single line: '4'

Test #35:

score: 0
Accepted
time: 1ms
memory: 4872kb

input:

6 2

output:

7

result:

ok single line: '7'

Test #36:

score: 0
Accepted
time: 3ms
memory: 4852kb

input:

500 2

output:

255888452

result:

ok single line: '255888452'

Test #37:

score: 0
Accepted
time: 3ms
memory: 4884kb

input:

8 3

output:

8

result:

ok single line: '8'

Test #38:

score: 0
Accepted
time: 3ms
memory: 4884kb

input:

9 3

output:

15

result:

ok single line: '15'