QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768334#8049. Equal SumsluozijinRE 0ms7768kbC++141.6kb2024-11-21 09:26:082024-11-21 09:26:10

Judging History

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

  • [2024-11-21 09:26:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:7768kb
  • [2024-11-21 09:26:08]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353
using namespace std;
const int N=510; 
int n,m,maxn,L[N][2],ans[N][N],R[N][2],f[2][N][N<<1];
void add(int &u,int v) {u+=v;if(u>=mod) u-=mod;if(u<0) u+=mod;}
int read(){char a=getchar();int res=0,f=1;while(!isdigit(a)) {if(a=='-') f=-1;a=getchar();}while(isdigit(a)) res=(res<<3)+(res<<1)+a-'0',a=getchar();return res*f;}
const int KK=22;int sta2[KK],tooot;
void write(int a,bool l){if(a<0) putchar('-'),a=-a;do{sta2[++tooot]=a%10;a/=10;}while(a);while(tooot) putchar(sta2[tooot]+'0'),tooot--;if(l) putchar(10);else putchar(32);}
signed main(){
	n=read();m=read();
	for(int i=1;i<=n;i++){
		L[i][0]=read();R[i][0]=read();
		maxn=max(R[i][0],maxn);
	}for(int i=1;i<=m;i++){
		L[i][1]=read();R[i][1]=read();
		maxn=max(R[i][1],maxn);
	}f[0][0][0+maxn]++;f[0][0][1+maxn]--;
	for(int i=0;i<=n;i++){
		int pr=i&1,nw=(i+1)&1;
		for(int j=0;j<=m;j++) for(int k=-maxn-1;k<=maxn+1;k++) f[nw][j][k]=0;
		for(int j=0;j<=m;j++){
			for(int k=-maxn;k<=maxn;k++){
				add(f[pr][j][k+maxn],f[pr][j][k-1+maxn]);
			}for(int k=-maxn;k<=0;k++){
				if(f[pr][j][k+maxn]){//cout<<i<<' '<<j<<' '<<k<<' '<<f[pr][j][k+maxn]<<endl;
					add(f[nw][j][k+L[i+1][0]+maxn],f[pr][j][k+maxn]);
					add(f[nw][j][k+R[i+1][0]+1+maxn],-f[pr][j][k+maxn]);
				}
			}for(int k=1;k<=maxn;k++){
				if(f[pr][j][k+maxn]){
					add(f[pr][j+1][k-R[j+1][1]+maxn],f[pr][j][k+maxn]);
					add(f[pr][j+1][k-L[j+1][1]+1+maxn],-f[pr][j][k+maxn]);
				}
			}ans[i][j]=f[pr][j][maxn];
		}
	}for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			write(ans[i][j],0);
		}putchar(10);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7768kb

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
Runtime Error

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:


result: