QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527542#8049. Equal Sums123456xwdML 0ms3824kbC++141.3kb2024-08-22 16:42:452024-08-22 16:42:45

Judging History

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

  • [2024-08-22 16:42:45]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:3824kb
  • [2024-08-22 16:42:45]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
#define p_b push_back
#define m_p make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define ls k<<1
#define rs k<<1|1
#define mid ((l+r)>>1)
#define gcd __gcd
#define lowbit(x) (x&(-x))
using namespace std;
int rd(){
    int x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if (ch=='-') f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
    return x*f;
}
void write(int x){
    if(x>9) write(x/10);
    putchar('0'+x%10);
}
const int N=500+5,V=500,INF=0x3f3f3f3f3f3f3f3f,mod=998244353;
int dp[N][N][V*2+100];
int a[N],b[N],c[N],d[N];
int n,m;
void add(int &x,int y){
	x+=y;
	if(x>=mod) x-=mod;
}
signed main(){
	n=rd(),m=rd();
	for(int i=1;i<=n;i++) a[i]=rd(),b[i]=rd();
	for(int i=1;i<=m;i++) c[i]=rd(),d[i]=rd();
	
	dp[0][0][V]=1;dp[0][0][V+1]=mod-1;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			for(int k=0;k<=V*2;k++){
				if(k)add(dp[i][j][k],dp[i][j][k-1]);
				if(k<=V){
					add(dp[i+1][j][k+a[i+1]],dp[i][j][k]),add(dp[i+1][j][k+b[i+1]+1],mod-dp[i][j][k]);	
				}
				if(k>V){
					add(dp[i][j+1][k-c[j+1]+1],mod-dp[i][j][k]),add(dp[i][j+1][k-d[j+1]],dp[i][j][k]);
				} 
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			printf("%d ",dp[i][j][V]);
		}
		puts("");
	}
    return 0;
}

詳細信息

Test #1:

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

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: