QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613966#8049. Equal Sumsfree_windyML 1ms7696kbC++201.1kb2024-10-05 15:12:172024-10-05 15:16:37

Judging History

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

  • [2024-10-05 15:16:37]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:7696kb
  • [2024-10-05 15:12:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int s=0,z=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')z=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		s=(s<<3)+(s<<1)+(c^48);
		c=getchar();
	}
	return s*z;
}
const int N = 505;
const int mod = 998244353;
int n,m;
long long f[N][N][N*2];
int la[N],lb[N],ra[N],rb[N];
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		la[i]=read(),ra[i]=read();
	}	
	for(int i=1;i<=m;i++){
		lb[i]=read(),rb[i]=read();
	}
	f[0][0][501]=1;
	for(int i=501;i<=1001;i++) f[0][0][i]=1;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(!i&&!j) continue;
			for(int k=1;k<=1001;k++){
				if(i!=0)f[i][j][k]=f[i-1][j][min(max(0,k-la[i]),501)]-f[i-1][j][min(max(0,k-ra[i]-1),501)];
				if(j!=0)f[i][j][k]+=f[i][j-1][max(min(1001,k+rb[j]),501)]-f[i][j-1][max(min(1001,k+lb[j]-1),501)];
				f[i][j][k]=(f[i][j][k]%mod+mod)%mod;
				f[i][j][k]=(f[i][j][k]+f[i][j][k-1])%mod;
				
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int l=1;l<=m;l++){
			cout<<f[i][l][501]-f[i][l][500]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3
1 2
2 3
1 4
2 2
1 3

output:

2 0 0 
3 4 4 

result:

ok 6 numbers

Test #2:

score: -100
Memory Limit Exceeded

input:

500 500
19 458
1 480
7 485
50 461
12 476
15 461
48 466
40 453
46 467
9 458
27 478
26 472
46 459
29 490
6 500
17 487
48 484
28 472
28 459
25 480
4 491
29 481
36 460
2 491
44 499
22 473
20 458
4 483
27 471
2 496
11 461
43 450
2 478
37 466
15 459
42 482
7 451
19 455
2 453
47 475
48 450
1 474
46 471
9 4...

output:

411 79401 9145270 -325239258 -817663288 -14021235 586589234 -705201083 404363796 -132882629 -332756365 118838806 -72054409 226338288 521479857 808644951 -212203065 -657475332 177100 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result: