QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462490 | #8534. Merging Cells | zlxFTH | 100 ✓ | 399ms | 101108kb | C++14 | 2.1kb | 2024-07-03 20:16:11 | 2024-07-03 20:16:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int P = 1e9 + 7;
struct mint {
int v;
mint(i64 x = 0) : v(x % P) {v < 0 ? v += P : 0;}
int val() const {return v;}
mint operator-() const {
return -v;
}
mint &operator+=(const mint &b) {
v += b.v - P, v += (v >> 31) & P;
return *this;
}
mint &operator-=(const mint &b) {
v -= b.v, v += (v >> 31) & P;
return *this;
}
mint &operator*=(const mint &b) {
v = i64(v) * b.v % P;
return *this;
}
mint &operator/=(const mint &b) {
return *this *= b.inv();
}
mint inv() const {
return this->pow(P - 2);
}
mint pow(i64 b) const {
mint c{1}, a = *this;
for (; b; a *= a, b /= 2) {
if (b & 1) c *= a;
}
return c;
}
friend mint operator+(mint a, const mint &b) {return a += b;}
friend mint operator-(mint a, const mint &b) {return a -= b;}
friend mint operator*(mint a, const mint &b) {return a *= b;}
friend mint operator/(mint a, const mint &b) {return a /= b;}
friend ostream &operator<<(ostream &os, const mint &a) {
return os << a.val();
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n), s(n + 1);
for (int i = 0; i < n; i++) {
cin >> a[i];
s[i + 1] = s[i] + a[i];
}
vector<vector<mint>> f(n, vector<mint>(n));
vector<int> L(n), R(n);
vector<mint> sL(n), sR(n), iv(n + 1);
for (int i = 0; i < n; i++) {
L[i] = 0;
R[i] = n - 1;
iv[i + 1] = mint(i + 1).inv();
}
f[0][n - 1] = 1;
for (int len = n; len >= 1; len--) {
for (int i = 0; i + len - 1 < n; i++) {
int j = i + len - 1;
while (2 * (s[j + 1] - s[i]) < (s[j + 1] - s[L[j]])) {
sL[j] -= f[L[j]][j] * iv[j - L[j]];
L[j]++;
}
while (2 * (s[j + 1] - s[i]) <= (s[R[i] + 1] - s[i])) {
sR[i] -= f[i][R[i]] * iv[R[i] - i];
R[i]--;
}
f[i][j] += sR[i] + sL[j];
sL[j] += f[i][j] * iv[j - i];
sR[i] += f[i][j] * iv[j - i];
}
}
for (int i = 0; i < n; i++) {
cout << f[i][i] << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4.54545
Accepted
time: 0ms
memory: 3612kb
input:
3 1 1 1
output:
0 500000004 500000004
result:
ok 3 lines
Test #2:
score: 4.54545
Accepted
time: 0ms
memory: 3812kb
input:
4 3 1 1 1
output:
666666672 0 166666668 166666668
result:
ok 4 lines
Test #3:
score: 4.54545
Accepted
time: 0ms
memory: 3752kb
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: 1ms
memory: 3828kb
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: 0ms
memory: 3628kb
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: 1ms
memory: 3792kb
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: 0ms
memory: 3792kb
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: 0ms
memory: 3592kb
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: 4.54545
Accepted
time: 3ms
memory: 4076kb
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:
0 0 0 944690385 0 0 0 242612480 0 8399179 0 110163050 974893044 358272088 0 48228454 0 903505904 0 436484419 170792331 0 869676053 958607284 0 365663539 0 807223441 0 981882973 0 0 874745289 656498327 0 559963645 851751674 0 0 402437556 175433699 0 779453711 0 426106104 251439971 29863562 0 0 555682...
result:
ok 500 lines
Test #10:
score: 4.54545
Accepted
time: 3ms
memory: 4100kb
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:
811385979 0 610215428 0 87757340 0 919939119 771682257 270980776 0 498816472 551123229 267763889 664839610 0 837222560 0 0 708944582 0 0 0 684002016 632717694 589257460 0 203956391 0 978429764 284700982 0 0 0 594560376 0 275274805 0 0 972581513 0 0 0 852516900 0 494438657 512650326 0 0 0 143528383 0...
result:
ok 500 lines
Test #11:
score: 4.54545
Accepted
time: 0ms
memory: 4080kb
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:
219550305 0 714911865 914355347 425722375 0 287270375 873306369 0 520426479 0 154178288 304451217 979440447 0 123083495 283747050 0 0 894472695 160786859 0 724661549 126956312 0 0 356210328 869368577 861369406 176104628 501523228 0 910288385 0 178755315 983268255 0 426225536 0 304313430 0 612714082 ...
result:
ok 500 lines
Test #12:
score: 4.54545
Accepted
time: 3ms
memory: 4064kb
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:
915414025 0 0 832014390 0 166402878 420602804 0 0 244013831 545092900 0 423220387 0 0 459959160 0 230723519 0 0 372710264 77171507 560084304 0 0 120168601 378089495 0 278356006 0 255469038 0 0 880735996 0 465927752 755290601 0 218812558 0 355526108 506209998 0 0 477184725 290781557 0 0 0 972090374 0...
result:
ok 500 lines
Test #13:
score: 4.54545
Accepted
time: 3ms
memory: 4128kb
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:
0 971922128 0 493055940 776297862 797900721 0 690018794 0 235694104 0 653169320 224275481 0 7392470 0 244458276 699405675 24342018 0 0 0 795235181 918990258 0 763059164 0 512022387 0 978443409 912391299 0 367481348 0 921920655 0 308147555 0 0 632110339 0 0 549632361 324952499 0 151462604 0 0 1431916...
result:
ok 500 lines
Test #14:
score: 4.54545
Accepted
time: 3ms
memory: 4124kb
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:
805170135 0 912022910 538270163 0 617178774 0 832622356 0 17872483 654944146 0 115709567 445015515 943969408 0 910664711 0 681210029 983734652 0 923213099 0 0 232199184 0 237870211 947277992 0 137681121 0 3127508 0 0 0 58029612 863544856 0 0 120180403 0 939609590 0 741906821 781723892 0 781723892 28...
result:
ok 500 lines
Test #15:
score: 4.54545
Accepted
time: 382ms
memory: 100972kb
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:
458922946 742096185 0 626166162 146788531 109827284 0 239734577 0 304908679 726525861 452509215 0 0 830672843 0 117854274 0 907552918 861178103 679853722 0 772035104 772035104 24111138 826564686 0 548351040 132875916 0 752462723 0 806465544 0 0 562329029 0 469209473 0 0 0 0 724907860 0 410825399 0 7...
result:
ok 5000 lines
Test #16:
score: 4.54545
Accepted
time: 383ms
memory: 101040kb
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:
0 645981910 336792323 0 389023932 82091243 0 576210917 0 0 417373333 0 225237192 940733645 994030181 0 228575755 298001663 0 260831490 519098769 0 0 710562644 0 0 571581066 0 495542939 0 933388823 0 433388474 125512636 0 0 496076721 237180193 579990101 462370693 0 0 936644530 0 41154898 0 965630155 ...
result:
ok 5000 lines
Test #17:
score: 4.54545
Accepted
time: 383ms
memory: 101108kb
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:
0 0 552289238 0 799511842 0 0 775228945 460553858 460553858 0 521602906 0 28821828 668428975 881291305 0 755363808 63533005 0 737715375 0 690473593 0 0 0 238406347 0 931963344 0 249596840 529047262 0 84031312 0 856066390 916905689 0 568644166 0 929565746 83374769 0 918682201 0 200402727 0 658469308 ...
result:
ok 5000 lines
Test #18:
score: 4.54545
Accepted
time: 394ms
memory: 101084kb
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:
0 0 508887485 256429212 0 0 0 519637463 0 70969600 765041105 0 874174864 0 141335097 862138360 0 0 51154619 0 0 0 40112338 0 0 852288875 0 556578172 0 354780578 0 0 433337771 444635671 629030264 0 385977278 0 0 345426957 0 0 50099106 0 785932904 0 0 493847409 796544036 0 0 0 0 879623741 0 216427934 ...
result:
ok 5000 lines
Test #19:
score: 4.54545
Accepted
time: 378ms
memory: 101020kb
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:
0 36750418 33856271 0 123162722 763726526 0 532314737 604868029 833466471 0 0 26839981 0 0 353788743 28602626 0 0 369373406 428551841 0 127224018 989600465 182989771 0 296102599 512159712 0 35073642 519917347 0 425727283 0 0 848228083 0 191612988 213920798 0 782750024 39857410 875812260 0 535623505 ...
result:
ok 5000 lines
Test #20:
score: 4.54545
Accepted
time: 399ms
memory: 100976kb
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:
0 739780481 802098930 0 333798312 525741019 0 847822699 822863379 925472561 0 789269209 0 0 244240883 0 601660954 848313161 692784795 0 361706758 0 969407667 307455230 0 506020045 506020045 269520606 935091765 637492993 0 369601639 0 0 0 183999489 0 0 260726272 0 0 810604810 0 0 0 0 385877563 980224...
result:
ok 5000 lines
Test #21:
score: 4.54545
Accepted
time: 377ms
memory: 101036kb
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:
972138778 567242887 0 867914174 0 0 447334437 265978116 223893266 0 888153158 568103367 0 435642899 0 596143707 0 0 371451154 0 140402851 553418400 604723591 0 263756499 582869337 0 291732375 0 165940553 0 259118032 565097127 69478631 0 337697166 301223576 0 432993145 89367760 475824622 318278946 22...
result:
ok 5000 lines
Test #22:
score: 4.54545
Accepted
time: 390ms
memory: 100964kb
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:
0 875466870 0 0 545294203 455929687 632604044 0 575173095 0 0 0 0 587800216 0 0 69626938 256523181 125447062 0 992117271 0 0 307428926 0 357496258 260180216 387458199 837975438 243905329 0 243905329 189084803 104173301 0 449189463 0 0 0 810185388 0 865428269 95463997 0 423274894 0 493365478 21036165...
result:
ok 5000 lines