QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643963#5097. 小 P 爱学习lingying20 5ms10768kbC++141.4kb2024-10-16 09:00:222024-10-16 09:00:23

Judging History

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

  • [2024-10-16 09:00:23]
  • 评测
  • 测评结果:20
  • 用时:5ms
  • 内存:10768kb
  • [2024-10-16 09:00:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=1505,M=1.5e5+5;
const int mod=1e9+7;

int n,m,ans;
int a[M],f[N],g[N][N],h[N][N],fact[M],infact[M];

int qpow(int a,int n)
{
	int ret=1;
	while(n)
	{
		if(n&1)ret=1ll*ret*a%mod;
		a=1ll*a*a%mod;
		n>>=1;
	}
	return ret;
}

void prepare()
{
	fact[0]=1;
	for(int i=1;i<M;i++)fact[i]=1ll*fact[i-1]*i%mod;
	infact[M-1]=qpow(fact[M-1],mod-2);
	for(int i=M-2;i>=0;i--)infact[i]=1ll*infact[i+1]*(i+1)%mod;
}

int C(int n,int m){return 1ll*fact[n]*infact[m]%mod*infact[n-m]%mod;}

int main()
{
	prepare();
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n*m;i++)scanf("%d",&a[i]);
	f[0]=1;
	for(int i=1;i<=n*m;i++)
		for(int j=min(i,n);j>=1;j--)
			f[j]=(f[j]+1ll*a[i]*f[j-1])%mod;
	if(m==1)
	{
		for(int i=1;i<=n;i++)ans=(ans+1ll*qpow(i,n-i)*f[i])%mod;
		cout<<ans;
		return 0;
	}
	int B=sqrt(n);
	g[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=B;k++)
				g[i][j]=(g[i][j]+1ll*g[i-k][j-1]*infact[k*m-1])%mod;
	h[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n/B;j++)
			for(int k=B+1;k<=n;k++)
				h[i][j]=(h[i][j]+1ll*h[i-k][j-1]*infact[k*m-1])%mod;
	for(int i=1;i<=n;i++)
	{
		int sum=0;
		for(int j=0;j<=n;j++)
			for(int k=0;k<=i&&k<=n/B;k++)
				sum=(sum+1ll*h[j][k]*g[n-j][i-k]%mod*C(i,k))%mod;
		ans=(ans+1ll*sum*fact[n*m-i]%mod*f[i])%mod;
	}
	cout<<ans;
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 6968kb

input:

3 4
993987920 851664708 532496582 332334976 645105194 437392477 101400616 97233810 821968468 15736516 160047245 366079295

output:

570333029

result:

wrong answer expected 856280467, found 570333029

Subtask #2:

score: 20
Accepted

Test #6:

score: 20
Accepted
time: 4ms
memory: 4884kb

input:

1500 1
613884366 318223729 617843443 151365784 314748737 778479063 762692152 762329264 560579744 428619194 148701427 891734077 339222910 692588908 180829596 615884679 688697194 981930569 856072945 973079346 407508504 185723413 482150672 944412007 548582506 572572951 297202679 276708377 552007154 951...

output:

716155203

result:

ok answer is 716155203

Test #7:

score: 20
Accepted
time: 0ms
memory: 8840kb

input:

1500 1
203946163 790756155 31880785 670720617 578032803 978211419 545524799 831170430 315457214 749338870 938190926 540898693 117170175 508468198 195897869 709484408 168150734 28068910 476238051 310956365 503395574 743107920 510982871 175542616 164902400 496501356 853160049 134615547 571906411 30301...

output:

673014307

result:

ok answer is 673014307

Test #8:

score: 20
Accepted
time: 4ms
memory: 8568kb

input:

1500 1
84869614 166989354 747450885 318354182 468629235 310852979 837778150 431330542 629725556 461633318 144111853 780737550 448212230 156411054 529516696 532965288 832680007 171808740 578171819 138906067 646999869 577255724 520945848 191524210 279391236 118616133 475169973 656690767 921746491 9987...

output:

198503963

result:

ok answer is 198503963

Test #9:

score: 20
Accepted
time: 4ms
memory: 4920kb

input:

1499 1
653054925 109470906 390970530 717020107 646929995 899421577 656477148 115141158 124058719 903220561 887601227 113934280 646598227 504529205 978403334 635650813 901811669 184325048 298833048 186091439 832843285 538527614 73677668 381132501 123839498 905560988 920236941 52720461 219606200 25431...

output:

565990166

result:

ok answer is 565990166

Test #10:

score: 20
Accepted
time: 4ms
memory: 6084kb

input:

1497 1
726348046 512456833 173926091 538307623 418534968 683578224 30631565 693232361 653147127 421461401 806414082 850512423 756123873 289504683 545013209 173529651 842096476 390808284 208681427 719150123 742145616 983822793 273803111 726750786 437249415 689245884 935836777 828643432 623602409 9543...

output:

989909589

result:

ok answer is 989909589

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 5ms
memory: 10768kb

input:

100 42
544703372 456304555 178333752 808160596 628160657 264931494 810502429 20342061 203372934 920107110 466566652 470361058 680819469 879463750 668822108 781685938 40434324 800845096 913025163 971899062 986502509 122277391 523016525 579121406 413351231 882719635 632511496 453222515 350376424 37340...

output:

859429292

result:

wrong answer expected 294362854, found 859429292

Subtask #4:

score: 0
Runtime Error

Test #16:

score: 0
Runtime Error

input:

499 60
136856769 47869549 264538291 600887500 271130365 503375271 979728502 928286478 295751844 413206031 143796624 712745939 41348750 488666164 725432432 529794914 703056452 573552365 225245406 620490759 715276073 987544150 759181034 939466746 354701446 228245827 301255190 24876250 452483821 837389...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #21:

score: 0
Runtime Error

input:

1500 93
299567650 399978478 101776752 583392666 56762099 127237968 595272440 581887945 332400603 269986805 17840600 323055242 263161884 607605816 966029729 591250421 964262680 642691696 658567473 339363823 715151825 270553684 202478735 193930303 14517687 248178770 917823665 315265457 473654173 33965...

output:


result: