QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#307114#8049. Equal SumssuperguymjTL 3ms21152kbC++141.7kb2024-01-17 23:19:532024-01-17 23:19:53

Judging History

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

  • [2024-01-17 23:19:53]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:21152kb
  • [2024-01-17 23:19:53]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)

using namespace std;
typedef long long LL;
const int N=505,mod=998244353;
int n,m;
struct D{int l,r;} a[N],b[N];
LL ans[N][N];
unordered_map <int,LL> f[N][N];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

struct C
{
	vector <LL> flv,inv;

	C(int n):flv(n+1,0),inv(n+1,0)
	{
		flv[0]=1;
		rep(i,1,n) flv[i]=flv[i-1]*i%mod;
		inv[n]=getmi(flv[n],mod-2);
		repd(i,n,1) inv[i-1]=inv[i]*i%mod;
	}

	LL getmi(LL a,LL x)
	{
		LL rt=1;
		while(x)
		{
			if(x&1) rt=rt*a%mod;
			a=a*a%mod,x>>=1;
		}
		return rt;
	}

	LL val(int n,int m)
	{
		return n<m?0:flv[n]*inv[m]%mod*inv[n-m]%mod;
	}
} ;

void inc(LL &x,LL y)
{
	if((x+=y)>=mod) x-=mod;
}

unordered_map <int,LL> dp(unordered_map <int,LL> &f,int x)
{
	unordered_map <int,LL> g,h;
	for(auto i:f)
	{
		inc(g[i.first],i.second);
		inc(g[i.first+x],mod-i.second);
	}
	for(auto i:g) if(i.second) h[i.first]=i.second;
	return h;
}

int main()
{
	n=getint(),m=getint();
	rep(i,1,n) a[i].l=getint(),a[i].r=getint();
	rep(i,1,m) b[i].l=getint(),b[i].r=getint();
	
	C c(250000+1000);
	f[0][0][0]=1;
	rep(i,0,n) rep(j,0,m) if(i || j)
	{
		if(i) f[i][j]=dp(f[i-1][j],a[i].r-a[i].l+1);
		else f[i][j]=dp(f[i][j-1],b[j].r-b[j].l+1);
		if(i && j)
		{
			int len=0;
			rep(x,1,i) len-=a[x].l;
			rep(x,1,j) len+=b[x].r;
			for(auto x:f[i][j]) if(x.first<=len) 
				ans[i][j]=(ans[i][j]+x.second*c.val(len-x.first+i+j-1,i+j-1))%mod;
		}
	}
	rep(i,1,n)
	{
		rep(j,1,m) printf("%lld ",ans[i][j]);
		puts("");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 21152kb

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:


result: