QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#497146#8534. Merging Cellsgreen_gold_dog36.363636 24ms5628kbC++202.6kb2024-07-28 20:14:152024-07-28 20:14:15

Judging History

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

  • [2024-07-28 20:14:15]
  • 评测
  • 测评结果:36.363636
  • 用时:24ms
  • 内存:5628kb
  • [2024-07-28 20:14:15]
  • 提交

answer

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;

constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007, MAXN = 10'000;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;

random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());

template<typename T>
bool assign_max(T& a, T b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
bool assign_min(T& a, T b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
T square(T a) {
	return a * a;
}

template<>
struct std::hash<pair<ll, ll>> {
	ll operator() (pair<ll, ll> p) const {
		return ((__int128)p.first * MOD + p.second) % INF64;
	}
};

ll binpow(ll a, ll b) {
	return (b == 0 ? 1 : square(binpow(a, b / 2)) % MOD * (b % 2 ? a : 1) % MOD);
}

ll inv(ll x) {
	return binpow(x, MOD - 2);
}

ll f[MAXN], invf[MAXN];

void precalc() {
	f[0] = 1;
	for (ll i = 1; i < MAXN; i++) {
		f[i] = f[i - 1] * i % MOD;
	}
	invf[MAXN - 1] = inv(f[MAXN - 1]);
	for (ll i = MAXN - 1; i > 0; i--) {
		invf[i - 1] = invf[i] * i % MOD;
	}
}

ll Merge(ll n, ll k) {
	return f[n + k - 2] * invf[n - 1] % MOD;
}

void solve() {
	ll n;
	cin >> n;
	vector<ll> arr(n);
	vector<ll> pref(1, 0);
	for (ll i = 0; i < n; i++) {
		cin >> arr[i];
		pref.push_back(pref.back() + arr[i]);
	}
	vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n));
	for (ll i = 0; i < n; i++) {
		dp[i][i].resize(1, 1);
	}
	for (ll len = 2; len <= n; len++) {
		for (ll l = 0; l + len <= n; l++) {
			ll r = l + len - 1;
			dp[l][r].resize(len, 0);
			ll fir = 0, sec = 0;
			for (ll mid = l; mid < r; mid++) {
				if (pref[mid + 1] - pref[l] > pref[r + 1] - pref[mid + 1]) {
					for (ll num = 0; num < mid - l + 1; num++) {
						dp[l][r][num] = (dp[l][r][num] + dp[l][mid][num] * Merge(mid - l + 1, r - mid) % MOD) % MOD;
					}
				} else {
					for (ll num = 0; num < r - mid; num++) {
						dp[l][r][mid - l + 1 + num] = (dp[l][r][mid - l + 1 + num] + dp[mid + 1][r][num] * Merge(r - mid, mid - l + 1) % MOD) % MOD;
					}
				}
			}
		}
	}
	for (ll i = 0; i < n; i++) {
		cout << dp[0].back()[i] * invf[n - 1] % MOD << '\n';
	}
}

int main() {
	if (IS_FILE) {
		freopen("", "r", stdin);
		freopen("", "w", stdout);
	}
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
	precalc();
	ll t = 1;
	if (IS_TEST_CASES) {
		cin >> t;
	}
	for (ll i = 0; i < t; i++) {
		solve();
	}
}

详细


Pretests


Final Tests

Test #1:

score: 4.54545
Accepted
time: 1ms
memory: 3732kb

input:

3
1 1 1

output:

0
500000004
500000004

result:

ok 3 lines

Test #2:

score: 4.54545
Accepted
time: 1ms
memory: 3968kb

input:

4
3 1 1 1

output:

666666672
0
166666668
166666668

result:

ok 4 lines

Test #3:

score: 4.54545
Accepted
time: 1ms
memory: 3820kb

input:

8
3 4 1 2 3 3 3 2

output:

0
657142862
0
0
783333339
471428575
88095239
0

result:

ok 8 lines

Test #4:

score: 4.54545
Accepted
time: 24ms
memory: 5396kb

input:

100
22219 88363 24709 66933 38729 52064 49005 61722 10235 97544 47279 13256 94244 6679 96027 28037 77409 28986 73665 88576 82745 51774 16927 70466 9635 77724 46479 56399 69109 33727 11901 95488 76929 91327 15477 39320 46949 36496 37159 22594 61561 14057 5843 78090 29787 80660 68339 6986 42242 15632 ...

output:

0
147199192
0
468705712
0
433254077
0
92867286
0
218187048
0
0
248296051
0
355219410
0
375014238
0
119865432
853239659
465356438
0
0
574104485
0
900841331
0
718349475
811585283
0
0
973355017
0
673051878
0
369038878
125666809
0
274641783
0
493999699
0
0
272717308
0
750992859
236772840
0
0
0
65184813
...

result:

ok 100 lines

Test #5:

score: 4.54545
Accepted
time: 24ms
memory: 5420kb

input:

100
7 3 10 8 6 4 5 1 5 1 4 8 2 7 1 4 4 7 7 9 9 9 1 8 7 5 5 3 3 6 5 5 2 4 5 9 8 1 2 4 10 7 6 3 4 6 3 2 3 8 3 9 2 6 10 2 1 4 8 4 3 10 2 7 5 8 5 9 7 10 4 2 10 10 6 2 2 5 10 2 9 2 9 2 7 9 1 8 2 4 4 7 5 4 9 4 6 1 6 4

output:

0
0
417444578
891001365
928545208
0
250231451
0
267379737
0
639741670
576802900
0
240585328
0
129164779
894619340
579473784
795214947
757335304
351981242
532715030
0
988878501
845242604
0
862572685
0
782145348
198439227
0
622371225
0
529260235
399649058
248209927
523418917
0
0
0
789891804
937841438
...

result:

ok 100 lines

Test #6:

score: 4.54545
Accepted
time: 24ms
memory: 5360kb

input:

100
90671 30917 67197 12279 61795 56895 19192 74559 43255 98169 49862 48101 6348 40151 42248 5014 35065 39138 97003 93502 40056 86173 35527 87252 38838 56095 69010 49001 1474 33449 99708 42013 85751 49953 27736 91362 5670 65075 76628 53420 86139 40787 6951 64863 51368 33063 37428 38814 6264 59694 45...

output:

274847537
0
259027838
0
907282281
640057173
0
452462140
0
276353256
804249980
222059590
0
644077588
460348434
0
984666871
954000599
979066967
394923328
0
995960871
0
444620469
0
500322893
207595291
866492520
0
0
664560733
0
424882213
0
0
136734775
0
0
508972002
0
68405538
0
0
584067572
103556075
0
6...

result:

ok 100 lines

Test #7:

score: 4.54545
Accepted
time: 24ms
memory: 5628kb

input:

100
5 7 7 8 2 4 5 3 8 8 2 1 4 1 6 3 6 4 3 1 8 6 9 8 2 9 7 9 5 9 7 8 1 4 10 1 2 8 4 4 1 7 4 2 6 10 9 6 8 8 10 6 2 2 7 6 4 6 8 2 6 2 8 10 4 1 6 4 8 3 1 4 1 7 4 3 4 8 6 3 4 6 1 5 9 4 10 9 9 5 2 3 3 7 2 6 10 9 8 9

output:

0
431747002
254689893
37677323
0
540085435
823135258
0
473933766
593175356
0
0
386921471
0
575076489
0
59952670
705697494
136207983
0
353217213
0
312810217
3266828
0
722993069
0
988651631
0
109457861
0
903144736
0
0
181751678
0
0
282783750
0
527691320
0
958868465
0
0
759769304
992518607
717510175
0
...

result:

ok 100 lines

Test #8:

score: 4.54545
Accepted
time: 24ms
memory: 5360kb

input:

100
37289 91666 87390 86415 37795 1848 48833 49002 49870 95822 29953 1122 29330 54995 12454 12084 52310 73223 68396 30282 80915 72849 15669 24096 87242 13850 18418 32241 15174 17800 65534 30509 59392 4917 37307 41319 11870 68492 46174 40720 44948 41607 18242 50064 59884 50159 69088 74104 15621 89684...

output:

0
291146976
686151083
379128623
0
0
951721897
256879502
691415765
319941957
153031454
0
153031454
915595543
0
0
95934677
201732870
875142998
0
579128794
544952374
0
0
311303753
0
502484893
217586688
0
544014319
995708907
0
965697883
0
325205288
89875698
0
948452050
269028964
0
230920449
672482811
0
...

result:

ok 100 lines

Test #9:

score: 0
Time Limit Exceeded

input:

500
3 6 1 10 2 1 6 10 2 3 1 4 7 9 6 10 8 9 7 7 5 3 9 9 1 6 4 6 1 10 3 3 7 8 1 8 10 4 2 10 7 6 7 5 7 6 5 3 1 4 10 3 4 8 5 10 4 1 7 10 3 3 6 6 2 10 8 9 9 6 1 1 7 1 10 10 4 8 1 5 4 1 6 5 2 5 3 4 10 1 2 8 3 8 3 7 3 3 5 10 7 2 3 10 5 10 5 6 3 7 9 4 8 1 3 1 2 8 2 4 9 2 6 2 9 9 8 6 1 4 9 2 2 8 5 2 6 8 4 8 ...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

500
98890 28044 85451 24276 39192 4785 38627 66923 93881 53221 56524 80783 58324 34929 13256 39130 26694 2241 62897 1723 3679 19394 57458 90245 77475 34132 86030 82619 87801 91834 23627 8966 14632 82447 33017 99369 1855 83358 91903 39771 9477 735 93746 19156 91222 55084 10552 14559 15854 42223 8277 ...

output:


result:


Test #11:

score: 0
Time Limit Exceeded

input:

500
8 3 10 10 7 3 8 7 6 6 4 5 5 9 2 10 6 3 2 10 8 3 4 3 1 1 6 10 9 7 5 2 9 7 10 8 4 6 2 9 1 4 1 1 2 10 6 7 5 10 9 3 6 2 8 9 6 10 2 2 1 5 1 6 1 2 7 5 7 10 4 5 7 2 8 9 6 1 7 6 7 3 10 10 3 4 6 7 8 3 10 2 10 8 4 2 4 2 5 10 8 4 1 9 9 1 5 4 7 4 7 10 5 10 9 1 2 3 9 7 5 3 4 1 5 3 10 5 3 2 9 7 8 3 6 5 2 4 1 ...

output:


result:


Test #12:

score: 0
Time Limit Exceeded

input:

500
70491 5721 3236 23537 2563 22059 51890 11740 34563 92354 72986 67163 99021 11636 18290 80170 66619 93884 37923 39457 89868 98992 54363 9400 22469 51628 92852 32388 90948 50638 62672 6990 352 19003 3368 20746 38197 16752 70924 53913 94771 50737 9394 36949 58018 80459 35050 8754 13560 62519 28710 ...

output:


result:


Test #13:

score: 0
Time Limit Exceeded

input:

500
5 8 6 8 10 9 8 10 2 8 4 7 10 1 9 2 8 8 10 6 2 1 9 9 2 10 6 6 5 5 7 2 4 2 7 5 9 5 3 9 2 1 10 10 5 10 4 5 9 10 10 10 4 10 1 2 8 10 10 2 10 6 2 3 1 9 3 1 8 3 5 2 1 6 9 8 8 7 9 10 9 4 1 2 4 5 6 1 1 2 4 9 5 5 5 4 9 8 1 8 5 3 6 3 8 5 6 7 3 4 5 6 10 9 7 4 6 10 7 9 9 8 7 7 4 3 5 4 10 9 2 8 1 10 3 5 9 9 ...

output:


result:


Test #14:

score: 0
Time Limit Exceeded

input:

500
69199 22505 81567 56998 27522 56886 19782 31074 25395 88055 92231 21198 79522 94956 88613 11068 26992 6152 22133 38542 32799 71050 11932 23913 67538 49242 95115 71891 22260 91462 28116 43388 16945 4451 11529 87293 78515 24694 9575 48312 43286 49584 4620 88084 41384 10409 33979 82256 1265 7273 35...

output:


result:


Test #15:

score: 0
Time Limit Exceeded

input:

5000
6 4 3 4 8 6 5 6 5 6 7 6 1 3 5 2 5 1 6 10 4 1 2 2 4 8 4 10 9 4 9 4 7 4 2 8 4 10 1 2 2 4 10 3 5 3 7 4 4 6 9 10 2 6 9 2 3 1 3 9 6 7 10 4 8 5 10 10 7 2 9 7 4 2 2 10 7 4 8 9 6 10 5 2 6 8 6 8 6 10 7 2 8 4 8 6 1 5 1 1 6 6 7 10 3 3 9 2 5 7 3 7 9 6 10 4 5 2 6 1 3 5 4 1 2 7 8 3 1 4 10 9 1 3 4 6 8 5 2 1 5...

output:


result:


Test #16:

score: 0
Time Limit Exceeded

input:

5000
88827 93090 83756 69412 82632 74069 27796 65002 3601 38004 79157 6482 38296 44674 66874 18812 55197 55126 16189 67590 60942 15799 23611 95719 83571 7031 99373 14086 73367 9704 65524 56348 85247 75464 26395 23671 73970 94899 97973 94017 48292 35715 84445 20997 96521 22569 45791 54482 24781 70949...

output:


result:


Test #17:

score: 0
Time Limit Exceeded

input:

5000
2 2 8 4 8 1 4 7 3 2 1 4 2 4 5 7 2 9 9 4 8 5 9 1 1 1 7 3 5 4 7 10 6 10 4 5 7 4 6 4 4 8 1 5 3 7 1 8 3 4 2 6 10 5 1 7 6 7 4 9 6 4 6 10 6 10 1 3 3 8 3 9 4 8 3 8 9 1 2 1 4 3 10 2 6 5 9 2 9 2 8 2 9 9 9 1 5 8 2 8 10 8 8 6 8 4 10 3 8 6 9 8 6 3 10 7 2 3 6 10 7 5 9 8 4 1 2 3 5 10 3 8 7 3 5 8 10 8 10 10 2...

output:


result:


Test #18:

score: 0
Time Limit Exceeded

input:

5000
2940 28375 92173 96201 3900 22739 14112 47912 19044 44815 77156 35949 76135 55927 58154 95211 7383 40392 64806 15347 15871 15738 95244 49248 2327 63740 5558 86722 34233 73502 9015 20003 58739 60985 49200 15049 38693 23465 9372 77675 43651 15304 72415 47659 89002 29474 36500 72139 94047 12255 12...

output:


result:


Test #19:

score: 0
Time Limit Exceeded

input:

5000
10 10 8 5 8 8 3 6 10 8 3 4 9 3 4 10 6 4 1 7 10 5 9 10 8 6 6 8 7 7 10 1 10 4 1 7 1 9 6 3 8 8 7 1 6 7 5 4 7 9 2 3 10 9 9 10 10 6 1 5 8 6 5 5 3 4 6 6 4 6 9 1 2 3 1 4 8 8 4 1 4 1 4 4 1 4 1 2 6 3 9 10 9 8 5 4 9 2 2 2 4 10 4 6 3 4 3 1 4 7 7 6 10 2 3 8 6 5 9 3 10 5 8 3 4 1 9 10 4 8 2 6 3 1 4 1 4 4 1 9...

output:


result:


Test #20:

score: 0
Time Limit Exceeded

input:

5000
32222 52214 61792 3293 89331 88675 38688 88553 94232 82652 12498 53914 23963 4590 36754 13962 38200 41649 79142 51271 72204 18882 71894 46144 8922 17927 22357 67288 79626 57929 47001 71078 26392 21502 7645 61311 12912 2936 50259 6706 22860 92023 137 29367 6359 20549 72304 44157 40711 96197 3740...

output:


result:


Test #21:

score: 0
Time Limit Exceeded

input:

5000
10 5 1 5 1 3 8 9 10 2 6 5 1 8 7 9 6 1 7 1 8 8 6 2 8 10 6 8 4 7 3 4 7 9 6 9 6 5 6 6 6 9 9 1 4 5 7 6 7 1 6 3 3 7 7 8 1 6 1 3 5 7 2 4 1 4 6 1 7 3 2 8 9 5 5 7 7 7 1 10 3 3 10 4 5 8 2 10 8 2 8 8 1 4 5 4 4 4 10 4 6 1 5 10 8 8 9 5 9 3 3 9 10 7 8 8 8 5 1 5 5 2 8 8 1 2 7 10 9 7 5 5 4 10 4 5 7 10 9 3 3 5...

output:


result:


Test #22:

score: 0
Time Limit Exceeded

input:

5000
89038 99267 78358 3665 84416 77096 67466 56406 80355 4276 30516 247 2009 61685 43325 13486 67233 99042 67375 15406 67875 29778 30676 78737 40488 51926 78207 48028 45355 27750 17297 27573 95699 64906 41243 66945 21287 24538 13005 72604 44622 78317 69724 30768 51548 2610 92502 79535 79209 60082 7...

output:


result: