QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#453515#8049. Equal Sumsucup-team3282ML 0ms3732kbC++141.6kb2024-06-23 22:54:322024-06-23 22:54:33

Judging History

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

  • [2024-06-23 22:54:33]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:3732kb
  • [2024-06-23 22:54:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=510;
const int mod=998244353;
const int maxv=300;

int n,m;
int la[maxn],ra[maxn],lb[maxn],rb[maxn];
int f[maxn][maxn][maxv*2+10],s[maxn][maxn][maxv*2+10];

int pls(int x,int y){
	return x+y<mod?x+y:x+y-mod;
}

int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>la[i]>>ra[i];
	for(int j=1;j<=m;j++)
		cin>>lb[j]>>rb[j];
	
	for(int k=-maxv;k<=maxv;k++){
		if(la[1]<=k&&k<=ra[1])
			f[1][0][k+maxv+1]=1;
		s[1][0][k+maxv+1]=pls(s[1][0][k-1+maxv+1],f[1][0][k+maxv+1]);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
//			cout<<"---------------------"<<i<<' '<<j<<"---------------------"<<endl;
			for(int k=-maxv;k<=maxv;k++){
				if(k<=ra[i] && k-max(k,la[i])>=-maxv){
//					cout<<'\t'<<max(k-ra[i],-maxv)<<"~"<<k-max(k,la[i])<<" -> "<<k<<endl;
					f[i][j][k+maxv+1]=pls(pls(mod-s[i-1][j][max(k-ra[i],-maxv)-1 +maxv+1],
					                        s[i-1][j][k-max(k,la[i])+maxv+1]),f[i][j][k+maxv+1]);
				}
				if(-k+1<=rb[j] && k+max(-k+1,lb[j])<=maxv){
//					cout<<'\t'<<k+max(-k+1,lb[j])<<"~"<<min(k+rb[j],maxv)<<" -> "<<k<<endl;
					f[i][j][k+maxv+1]=pls(pls(mod-s[i][j-1][k+max(-k+1,lb[j])-1 +maxv+1],
					                        s[i][j-1][min(k+rb[j],maxv) +maxv+1]),f[i][j][k+maxv+1]);
				}
//				cout<<"f "<<i<<' '<<j<<' '<<k<<' '<<f[i][j][k+maxv+1]<<endl;
				s[i][j][k+maxv+1]=pls(s[i][j][k-1+maxv+1],f[i][j][k+maxv+1]);
			}
		}
	}
		
	
	for(int i=1;i<=n;i++,cout<<endl)
		for(int j=1;j<=m;j++)
			cout<<f[i][j][maxv+1]<<' ';
	
	
	return 0;
}

詳細信息

Test #1:

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

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:

253 28920 1823471 64684950 369289507 321579783 911819072 179865406 455257174 416949810 901983192 17383860 14 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 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: