QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#364038#8049. Equal Sumsucup-team2219#TL 1ms7944kbC++142.0kb2024-03-24 10:35:112024-03-24 10:35:12

Judging History

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

  • [2024-03-24 10:35:12]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7944kb
  • [2024-03-24 10:35:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[505][2],b[505][2];
int dp[2][505][1005],sum[2][505][1005],nw=0;
const int mod=998244353;
int M(int x)
{
	if(x>=mod)return x-mod;
	if(x<0)return x+mod;
	return x;
}
int ask(int u,int v,int l,int r)
{
	if(l>r)return 0;
	return sum[u][v][r]-sum[u][v][l-1];
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i][0],&a[i][1]);
	for(int i=1;i<=m;i++)scanf("%d%d",&b[i][0],&b[i][1]);
	nw=0;
	//dp[0][0].resize(1005,0);
	//sum[0][0].resize(1005,0);
	dp[0][0][501]=1;
	for(int i=1;i<=1002;i++)sum[0][0][i]=M(sum[0][0][i-1]+dp[0][0][i]);
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(i==0&&j==0)continue;
			for(int k=1;k<=1001;k++)
			{
				dp[nw][j][k]=sum[nw][j][k]=0;
				if(j>0)
				{
					int ly=501,ry=1001;
					ly=max(501,k+b[j][0]);
					ry=min(1001,k+b[j][1]);
					//if(i==1&&j==1&&k==501)printf("#%d %d\n",ly,ry);
					dp[nw][j][k]=M(dp[nw][j][k]+M(ask(nw,j-1,ly,ry)));
					//if(k>=497&&k<=505)printf("#%d %d:%d %d %d %d\n",ly,ry,i,j,k-501,dp[nw][j][k]);
					//if(i==1&&j==1&&k==501)printf("#%d\n",dp[i][j][k]);
				}
				if(i>0)
				{
					int ly=1,ry=501;
					ly=max(1,k-a[i][1]);
					ry=min(501,k-a[i][0]);
					dp[nw][j][k]=M(dp[nw][j][k]+M(ask(!nw,j,ly,ry)));
				//	if(i==1&&j==0&&k>=497&&k<=505&&k==502)printf("%d %d %d:%d %d %d %d\n",nw,ly,ry,i,j,k-501,dp[nw][j][k]);
					//if(i==1&&j==1&&k==501)printf("#%d\n",dp[i][j][k]);
					if(j>0)
					{
						ly=max(501-b[j][1],k-a[i][1]);
						ry=min(501-b[j][0],k-a[i][0]);
						dp[nw][j][k]=M(1ll*dp[nw][j][k]-1ll*dp[!nw][j-1][501]*max(0ll,1ll*(ry-ly+1))%mod);
					}	
				}
			}
			if(i>0&&j>0)
			{
			printf("%d",dp[nw][j][501]);
			if(j==m)printf("\n");
			else printf(" ");
			}
			for(int k=1;k<=1001;k++)sum[nw][j][k]=M(sum[nw][j][k-1]+dp[nw][j][k]);
			//if(i>=2)vector<int>().swap(dp[i-2][j]),vector<int>().swap(sum[i-2][j]);
		}
		nw=!nw;
	}	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time 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 673005095 180581065 984223118 586589234 293043270 404363796 865361724 665487988 118838806 926189944 226338288 521479857 808644951 786041288 340769021 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 0 0 0 ...

result: