QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#670414#8049. Equal SumseastcloudML 1ms3616kbC++141.7kb2024-10-23 21:37:282024-10-23 21:37:29

Judging History

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

  • [2024-10-23 21:37:29]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:3616kb
  • [2024-10-23 21:37:28]
  • 提交

answer

#include<bits/stdc++.h>

#define vi vector<int>
#define fi first
#define se second
#define mp make_pair
#define pi pair<int,int>
#define ary array<int>
#define all(x) begin(x),end(x)
#define pb emplace_back
#define IL inline

using namespace std;

#define N 505
#define mod 998244353
#define B 501

int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
	while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
void write(int x){
	if(x<0)x=-x,putchar('-');
	if(x/10)write(x/10);
	putchar(x%10+'0');
}

pi a[N],b[N];

IL int pls(int x,int y){return (x+y>=mod?x+y-mod:x+y);}
IL int sub(int x,int y){return (x-y<0?x-y+mod:x-y);}
IL void Add(int &x,int y){x=pls(x,y);}
IL void Dec(int &x,int y){x=sub(x,y);}
IL int mul(int x,int y){return x*1ll*y%mod;}

int f[N][N][2*N],g[N][N][2*N];

int main(){
	#ifdef EAST_CLOUD
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	
	int n=read(),m=read();
	for(int i=1;i<=n;i++)a[i].fi=read(),a[i].se=read();
	for(int i=1;i<=m;i++)b[i].fi=read(),b[i].se=read();
	
	
	g[0][0][B]=1;g[0][0][B+1]=mod-1;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			for(int V=-B+1;V<=B;V++){
				f[i][j][V+B]=pls(f[i][j][V+B-1],g[i][j][V+B]);
				if(V<0){
					if(i==n)continue;
					Add(g[i+1][j][V+a[i+1].fi+B],f[i][j][V+B]);
					Dec(g[i+1][j][V+a[i+1].se+B+1],f[i][j][V+B]);					
				}
				else{
					if(j==m)continue;
					Add(g[i][j+1][V-b[j+1].se+B],f[i][j][V+B]);
					Dec(g[i][j+1][V-b[j+1].fi+B+1],f[i][j][V+B]);
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)write(f[i][j][B]),putchar(' ');
		putchar('\n');
	}
	return 0;
}

詳細信息

Test #1:

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

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 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: