QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#806119#9782. NonZero PrefSuf Sumsucup-team5008#AC ✓577ms419512kbC++233.0kb2024-12-08 21:47:252024-12-08 21:47:25

Judging History

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

  • [2024-12-08 21:47:25]
  • 评测
  • 测评结果:AC
  • 用时:577ms
  • 内存:419512kb
  • [2024-12-08 21:47:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const ll inf=LLONG_MAX/4;
#define rep2(i,j,k) for(ll i=ll(j);i<ll(k);i++)
#define rep(i,k) rep2(i,0,k)
#define rrep2(i,j,k) for(ll i=ll(j)-1;i>=ll(k);i--)
#define rrep(i,k) rrep2(i,k,0)
#define eb emplace_back
#define SZ(a) ll(a.size())
#define all(a) a.begin(),a.end()
template<class T>
bool chmin(T& a, T b){return a>b?a=b,1:0;}
template<class T>
bool chmax(T& a, T b){return a<b?a=b,1:0;}

int mod = 1;

struct mint {
	int x;
	mint(ll x = 0) : x((x%mod+mod)%mod) {}

	mint &operator+=(const mint &a) { if((x += a.x) >= mod) x -= mod; return *this; }
	mint &operator-=(const mint &a) { if((x += mod-a.x) >= mod) x -= mod; return *this; }
	mint &operator*=(const mint &a) { x = (ll) x * a.x % mod; return *this; }

	mint operator+(const mint &a) { return mint(*this) += a; }
	mint operator-(const mint &a) { return mint(*this) -= a; }
	mint operator*(const mint &a) { return mint(*this) *= a; }

	mint pow(ll t) {
		mint res(1), a(*this);
		while(t) {
			if(t&1) res *= a;
			a *= a;
			t >>= 1;
		}
		return res;
	}
};

mint dp[101][101][10001];

mint sub[101][20001];

const int C = 100000;
mint fac[C+1], ifac[C+1];
mint binom(int n, int k) {
	assert(n >= 0);
	if(k < 0 or k > n) return 0;
	return fac[n] * ifac[k] * ifac[n-k];
}

mint A[110][10010];
mint B[110][10010];

int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m >> mod;
	fac[0] = 1;
	rep(i, C) fac[i+1] = fac[i] * (i+1);
	ifac[C] = fac[C].pow(mod-2);
	rrep(i, C) ifac[i] = ifac[i+1] * (i+1);
	dp[0][0][0] = 1;
	rep(i, n) {
		rep(j, m+1) rep(k, (i+1)*j+1) A[j][k] = B[j][k] = 0;
		rep(j, m+1) rep(k, i*j+1) {
			A[j][k+1] += dp[i][j][k];
			A[j][k+j+1] -= dp[i][j][k];
			B[j+1][k+j+1] += dp[i][j][k];
		//	rep2(l, 1, m+1) dp[i+1][max(j,l)][k+l] += dp[i][j][k];
		}
		rep(j, m+1) rep(k, (i+1)*j+1) {
			A[j][k+1] += A[j][k];
			B[j+1][k+1] += B[j][k];
			dp[i+1][j][k] += A[j][k];
			dp[i+1][j][k] += B[j][k];
		}
	}
//	rep2(i, 1, n+1) rep(k, i*m+1) {
//		mint pre;
//		rep2(j, 1, m+1) {
//			mint now;
//			if(i*j < k) continue;
//			rep(l, i+1) {
//				if(l*(j+1) > k) continue;
//				mint tmp = binom(i, l) * binom(k-l*(j+1)+i-1, i-1);
//				if(l&1) now -= tmp;
//				else now += tmp;
//			}
//			assert((now-pre).x == dp[i][j][k].x);
//			pre = now;
//		}
//	}
	sub[0][0] = 1;
	rep(i, n) rep(j, 2*m*i+1) rep(k, 2*m+1) if(k != m) sub[i+1][j+k] += sub[i][j];
	mint ans;
	rep(i, n+1) rep(j, m+1) rrep(k, n*m) dp[i][j][k] += dp[i][j][k+1];
	rep2(i, 2, n+1) {
		mint now;
		rep2(a, 1, m+1) rep2(j, 1, i+1) rep(k, m/a+1) {
			mint tmp;
			int lb = max(0LL, j-k-1);
			int ub = j;
			assert(lb <= ub);
			tmp += dp[i-j][k][lb];
			tmp -= dp[i-j][k][ub];
			//rep2(l, lb, ub) {
			//	tmp += dp[i-j][k][l];
			//}
			now += tmp * binom(i, j);
		}
		now *= 2;
		now += sub[i][i*m];
		mint cur = 1;
		rep(_, i) cur *= 2*m;
		cur -= now;
		cur *= binom(n, i);
		ans += cur;
	}
	cout << ans.x << endl;
}

詳細信息

Test #1:

score: 100
Accepted
time: 19ms
memory: 419452kb

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #2:

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

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #3:

score: 0
Accepted
time: 23ms
memory: 419368kb

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 64ms
memory: 419392kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #5:

score: 0
Accepted
time: 140ms
memory: 419448kb

input:

61 75 677323601

output:

34613998

result:

ok single line: '34613998'

Test #6:

score: 0
Accepted
time: 27ms
memory: 419360kb

input:

13 14 670577333

output:

41465431

result:

ok single line: '41465431'

Test #7:

score: 0
Accepted
time: 27ms
memory: 419460kb

input:

14 6 987686347

output:

37536510

result:

ok single line: '37536510'

Test #8:

score: 0
Accepted
time: 31ms
memory: 419396kb

input:

15 12 196428923

output:

29322522

result:

ok single line: '29322522'

Test #9:

score: 0
Accepted
time: 40ms
memory: 419512kb

input:

68 7 786815587

output:

149281835

result:

ok single line: '149281835'

Test #10:

score: 0
Accepted
time: 23ms
memory: 419460kb

input:

3 2 503002109

output:

82

result:

ok single line: '82'

Test #11:

score: 0
Accepted
time: 32ms
memory: 419508kb

input:

13 5 756093197

output:

415698676

result:

ok single line: '415698676'

Test #12:

score: 0
Accepted
time: 27ms
memory: 419392kb

input:

2 3 646574611

output:

30

result:

ok single line: '30'

Test #13:

score: 0
Accepted
time: 59ms
memory: 419392kb

input:

39 68 120037189

output:

43217507

result:

ok single line: '43217507'

Test #14:

score: 0
Accepted
time: 24ms
memory: 419456kb

input:

13 4 423132517

output:

360231790

result:

ok single line: '360231790'

Test #15:

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

input:

14 3 309713387

output:

94215386

result:

ok single line: '94215386'

Test #16:

score: 0
Accepted
time: 43ms
memory: 419512kb

input:

24 77 886983941

output:

211636479

result:

ok single line: '211636479'

Test #17:

score: 0
Accepted
time: 7ms
memory: 419460kb

input:

3 3 504388063

output:

270

result:

ok single line: '270'

Test #18:

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

input:

3 1 936205423

output:

8

result:

ok single line: '8'

Test #19:

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

input:

3 3 295983139

output:

270

result:

ok single line: '270'

Test #20:

score: 0
Accepted
time: 23ms
memory: 419448kb

input:

10 15 446169107

output:

149884328

result:

ok single line: '149884328'

Test #21:

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

input:

37 18 833753929

output:

592917251

result:

ok single line: '592917251'

Test #22:

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

input:

11 3 998773403

output:

860630017

result:

ok single line: '860630017'

Test #23:

score: 0
Accepted
time: 31ms
memory: 419452kb

input:

14 85 688036639

output:

347188409

result:

ok single line: '347188409'

Test #24:

score: 0
Accepted
time: 32ms
memory: 419468kb

input:

3 3 844621907

output:

270

result:

ok single line: '270'

Test #25:

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

input:

3 4 204335891

output:

620

result:

ok single line: '620'

Test #26:

score: 0
Accepted
time: 27ms
memory: 419384kb

input:

7 8 113007667

output:

58946097

result:

ok single line: '58946097'

Test #27:

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

input:

4 1 637268377

output:

22

result:

ok single line: '22'

Test #28:

score: 0
Accepted
time: 24ms
memory: 419464kb

input:

11 14 391637237

output:

303270280

result:

ok single line: '303270280'

Test #29:

score: 0
Accepted
time: 32ms
memory: 419460kb

input:

3 2 208286231

output:

82

result:

ok single line: '82'

Test #30:

score: 0
Accepted
time: 7ms
memory: 419412kb

input:

2 11 662696483

output:

462

result:

ok single line: '462'

Test #31:

score: 0
Accepted
time: 23ms
memory: 419396kb

input:

19 55 974135299

output:

887460557

result:

ok single line: '887460557'

Test #32:

score: 0
Accepted
time: 23ms
memory: 419448kb

input:

6 8 417027509

output:

23351024

result:

ok single line: '23351024'

Test #33:

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

input:

8 13 624006587

output:

353008442

result:

ok single line: '353008442'

Test #34:

score: 0
Accepted
time: 24ms
memory: 419396kb

input:

10 10 740294671

output:

79436611

result:

ok single line: '79436611'

Test #35:

score: 0
Accepted
time: 7ms
memory: 419392kb

input:

11 10 394088657

output:

161476458

result:

ok single line: '161476458'

Test #36:

score: 0
Accepted
time: 23ms
memory: 419512kb

input:

9 27 562853573

output:

135252259

result:

ok single line: '135252259'

Test #37:

score: 0
Accepted
time: 23ms
memory: 419448kb

input:

8 3 829129009

output:

5349034

result:

ok single line: '5349034'

Test #38:

score: 0
Accepted
time: 51ms
memory: 419468kb

input:

51 49 924010279

output:

815049368

result:

ok single line: '815049368'

Test #39:

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

input:

12 2 308466749

output:

223013998

result:

ok single line: '223013998'

Test #40:

score: 0
Accepted
time: 11ms
memory: 419480kb

input:

7 4 567557693

output:

4502296

result:

ok single line: '4502296'

Test #41:

score: 0
Accepted
time: 84ms
memory: 419388kb

input:

36 93 943780729

output:

13599465

result:

ok single line: '13599465'

Test #42:

score: 0
Accepted
time: 11ms
memory: 419388kb

input:

2 1 828681127

output:

2

result:

ok single line: '2'

Test #43:

score: 0
Accepted
time: 27ms
memory: 419456kb

input:

3 3 534160729

output:

270

result:

ok single line: '270'

Test #44:

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

input:

7 12 920925433

output:

453086694

result:

ok single line: '453086694'

Test #45:

score: 0
Accepted
time: 19ms
memory: 419448kb

input:

3 2 440546987

output:

82

result:

ok single line: '82'

Test #46:

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

input:

90 9 291269963

output:

72560304

result:

ok single line: '72560304'

Test #47:

score: 0
Accepted
time: 23ms
memory: 419444kb

input:

38 10 867575113

output:

165530481

result:

ok single line: '165530481'

Test #48:

score: 0
Accepted
time: 40ms
memory: 419384kb

input:

48 37 152663531

output:

135425620

result:

ok single line: '135425620'

Test #49:

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

input:

15 15 991731803

output:

102703562

result:

ok single line: '102703562'

Test #50:

score: 0
Accepted
time: 577ms
memory: 419464kb

input:

100 100 696969697

output:

313377809

result:

ok single line: '313377809'

Extra Test:

score: 0
Extra Test Passed