QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#269318#7774. 基础寄术练习题275307894a100 ✓198ms19548kbC++141.7kb2023-11-29 15:06:382023-11-29 15:06:41

Judging History

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

  • [2023-11-29 15:06:41]
  • 评测
  • 测评结果:100
  • 用时:198ms
  • 内存:19548kb
  • [2023-11-29 15:06:38]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=100+5,M=8e5+5,K=(1<<25)+5,mod=1e9+9,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,k,p,lim;ll inv[N*N];
namespace Solve1{
	ll f[N][N];
	void solve(){
		int i,j;f[0][0]=1;
		for(i=1;i<=m;i++){
			for(j=0;j<=n;j++) f[i][j]=f[i-1][j];
			for(j=1;j<=n;j++) f[i][j]=(f[i-1][j-1]*inv[i]+f[i-1][j])%p;
		}
		printf("%lld\n",f[m][n]);
	}
}
namespace Solve2{
	ll f[N][N*N/2][2],g[N][N*N/2][2];
	void solve(){
		int i,j,h;lim=n*(m+m-n+1)/2;
		f[0][0][0]=1;
		for(i=1;i<=m;i++){
			Mc(g,f);
			for(j=1;j<=n&&j<=i;j++) {
				int l2=(i+i-j+1)*j/2;
				for(h=0;h<=l2;h++) for(int o=0;o<2;o++) f[j][h][o]=(f[j][h][o]+g[j-1][h][o]*inv[i])%p;
				for(h=i;h<=l2;h++) for(int o=0;o<2;o++) f[j][h][o]=(f[j][h][o]+g[j-1][h-i][o]*(p-inv[i])%p)%p;
				for(h=i;h<=l2;h++) f[j][h][1]=(f[j][h][1]+g[j-1][h-i][0]*i)%p;
			}
		}
		ll ans=0;for(i=0;i<=lim;i++) ans+=f[n][i][1]*inv[i]%p;
		printf("%lld\n",ans%p);
	}
}
void Solve(){
	int i,j,h;scanf("%d%d%d%d",&n,&m,&k,&p);
	inv[0]=inv[1]=1;for(i=2;i<=n*m;i++) inv[i]=(p-inv[p%i])*(p/i)%p;
	if(k==1) Solve1::solve();
	else Solve2::solve();
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 4020kb

input:

9 16 1 327134593

output:

162102742

result:

ok single line: '162102742'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

11 18 1 834359503

output:

256188485

result:

ok single line: '256188485'

Test #3:

score: 0
Accepted
time: 0ms
memory: 4048kb

input:

18 18 1 614802701

output:

552168146

result:

ok single line: '552168146'

Test #4:

score: 0
Accepted
time: 8ms
memory: 13280kb

input:

7 16 2 861918403

output:

306693876

result:

ok single line: '306693876'

Test #5:

score: 0
Accepted
time: 12ms
memory: 13732kb

input:

11 17 2 617904383

output:

393900291

result:

ok single line: '393900291'

Subtask #2:

score: 25
Accepted

Test #6:

score: 25
Accepted
time: 1ms
memory: 4132kb

input:

60 98 1 715015339

output:

690737273

result:

ok single line: '690737273'

Test #7:

score: 0
Accepted
time: 1ms
memory: 4140kb

input:

96 97 1 507892589

output:

481151247

result:

ok single line: '481151247'

Test #8:

score: 0
Accepted
time: 1ms
memory: 4144kb

input:

90 95 1 621080027

output:

255353202

result:

ok single line: '255353202'

Test #9:

score: 0
Accepted
time: 1ms
memory: 4140kb

input:

85 94 1 297115421

output:

122254364

result:

ok single line: '122254364'

Test #10:

score: 0
Accepted
time: 1ms
memory: 4076kb

input:

81 91 1 460412027

output:

148037986

result:

ok single line: '148037986'

Subtask #3:

score: 15
Accepted

Test #11:

score: 15
Accepted
time: 18ms
memory: 15152kb

input:

29 29 2 545875273

output:

171843225

result:

ok single line: '171843225'

Test #12:

score: 0
Accepted
time: 15ms
memory: 13496kb

input:

29 29 2 342070607

output:

291380196

result:

ok single line: '291380196'

Test #13:

score: 0
Accepted
time: 14ms
memory: 15012kb

input:

30 30 2 293965439

output:

148471965

result:

ok single line: '148471965'

Test #14:

score: 0
Accepted
time: 16ms
memory: 13648kb

input:

30 30 2 528219961

output:

203632962

result:

ok single line: '203632962'

Test #15:

score: 0
Accepted
time: 0ms
memory: 4056kb

input:

30 30 1 202836509

output:

158493990

result:

ok single line: '158493990'

Subtask #4:

score: 10
Accepted

Test #16:

score: 10
Accepted
time: 18ms
memory: 13944kb

input:

27 30 2 360712453

output:

80987914

result:

ok single line: '80987914'

Test #17:

score: 0
Accepted
time: 15ms
memory: 13308kb

input:

26 29 2 377615957

output:

278812897

result:

ok single line: '278812897'

Test #18:

score: 0
Accepted
time: 16ms
memory: 14536kb

input:

22 30 2 163686233

output:

19517828

result:

ok single line: '19517828'

Test #19:

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

input:

20 29 2 785657729

output:

713061509

result:

ok single line: '713061509'

Test #20:

score: 0
Accepted
time: 0ms
memory: 4044kb

input:

24 29 1 374090597

output:

312615700

result:

ok single line: '312615700'

Subtask #5:

score: 15
Accepted

Test #21:

score: 15
Accepted
time: 27ms
memory: 14840kb

input:

29 38 2 909155077

output:

745973305

result:

ok single line: '745973305'

Test #22:

score: 0
Accepted
time: 30ms
memory: 14004kb

input:

40 40 2 1067474879

output:

995503334

result:

ok single line: '995503334'

Test #23:

score: 0
Accepted
time: 22ms
memory: 14404kb

input:

32 37 2 751116719

output:

699924081

result:

ok single line: '699924081'

Test #24:

score: 0
Accepted
time: 25ms
memory: 13836kb

input:

33 37 2 496100951

output:

21741458

result:

ok single line: '21741458'

Test #25:

score: 0
Accepted
time: 0ms
memory: 4084kb

input:

34 38 1 499914887

output:

386116226

result:

ok single line: '386116226'

Subtask #6:

score: 10
Accepted

Test #26:

score: 10
Accepted
time: 66ms
memory: 15996kb

input:

57 66 2 767174999

output:

315351738

result:

ok single line: '315351738'

Test #27:

score: 0
Accepted
time: 68ms
memory: 15820kb

input:

52 69 2 399947623

output:

237685494

result:

ok single line: '237685494'

Test #28:

score: 0
Accepted
time: 60ms
memory: 14776kb

input:

63 64 2 903693961

output:

520250635

result:

ok single line: '520250635'

Test #29:

score: 0
Accepted
time: 80ms
memory: 15792kb

input:

65 70 2 268454909

output:

255864893

result:

ok single line: '255864893'

Test #30:

score: 0
Accepted
time: 0ms
memory: 4128kb

input:

58 68 1 562105223

output:

175445185

result:

ok single line: '175445185'

Subtask #7:

score: 15
Accepted

Test #31:

score: 15
Accepted
time: 198ms
memory: 19548kb

input:

96 96 2 453296971

output:

222864385

result:

ok single line: '222864385'

Test #32:

score: 0
Accepted
time: 191ms
memory: 17972kb

input:

85 96 2 859572601

output:

457416092

result:

ok single line: '457416092'

Test #33:

score: 0
Accepted
time: 177ms
memory: 18612kb

input:

89 94 2 753918677

output:

366789523

result:

ok single line: '366789523'

Test #34:

score: 0
Accepted
time: 169ms
memory: 18612kb

input:

91 92 2 202806031

output:

64270709

result:

ok single line: '64270709'

Test #35:

score: 0
Accepted
time: 1ms
memory: 4180kb

input:

100 100 1 493945957

output:

109570004

result:

ok single line: '109570004'