ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214758 | #2161. 小L的栈 | KXG | 100 | 1728ms | 47384kb | C++11 | 1.1kb | 2024-11-21 18:55:04 | 2024-11-22 09:30:12 |
answer
#include <cstdio>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2000000;
long long t, n, m, k;
long long inv[2000010], invfac[2000010], fac[2000010];
long long C(long long n, long long m) {
if (n < m) return 0;
return fac[n] * invfac[m] % mod * invfac[n - m] % mod;
}
long long Catalan(long long n, long long m, long long k) {
if (n < 0 || m < 0) return 0;
if (m < k) {
return C(n + m, m);
} else if (k <= m && m <= n + k - 1) {
return (C(n + m, m) - C(n + m, m - k) + mod) % mod;
} else {
return 0;
}
}
long long solve(long long n, long long m, long long k) {
return Catalan(m - 1, m - k, 1) * Catalan(n - m, n - m + k, k + 1) % mod;
}
int main() {
inv[1] = invfac[0] = invfac[1] = fac[0] = fac[1] = 1;
for (int i = 2; i <= maxn; i++) {
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
invfac[i] = invfac[i - 1] * inv[i] % mod;
fac[i] = fac[i - 1] * i % mod;
}
scanf("%lld", &t);
while (t--) {
scanf("%lld%lld%lld", &n, &m, &k);
printf("%lld\n", solve(n, m, k));
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 91ms
memory: 47384kb
input:
100 26 20 10 26 24 9 13 2 2 21 13 4 29 7 5 22 19 13 12 1 1 26 1 1 24 20 2 17 15 15 3 1 1 24 14 17 25...
output:
514423014 112607261 534888 381817972 555144047 73489416 208012 352943583 53685987 152 5 0 946367425 ...
result:
ok 100 lines
Test #2:
score: 5
Accepted
time: 80ms
memory: 47380kb
input:
100 13 6 3 12 6 3 14 14 13 24 15 9 8 6 5 4 3 1 4 3 2 18 12 7 23 11 5 24 20 14 14 7 3 27 21 17 31 17 ...
output:
198016 56056 13 366737601 135 4 6 39504192 967067366 715926750 636480 64591509 0 671918485 796107692...
result:
ok 100 lines
Test #3:
score: 5
Accepted
time: 88ms
memory: 47380kb
input:
100 31 18 12 11 3 1 27 9 9 7 6 2 21 15 6 16 2 1 18 11 12 22 17 5 15 6 1 10 8 10 23 22 6 28 5 6 23 4 ...
output:
661234655 9724 815886766 126 267452475 9694845 0 656127752 705432 0 581024202 0 78189099 2674440 1 4...
result:
ok 100 lines
Test #4:
score: 5
Accepted
time: 82ms
memory: 47384kb
input:
100 25 22 14 7 5 6 6 1 1 7 1 1 7 4 2 8 5 1 8 2 1 18 4 5 5 4 3 18 9 7 11 10 6 4 2 1 15 4 2 3 1 1 3 1 ...
output:
594796736 0 132 429 140 196 429 0 12 33649000 3003 5 2674440 5 5 858 24310 823378651 935508470 0 856...
result:
ok 100 lines
Test #5:
score: 5
Accepted
time: 83ms
memory: 47380kb
input:
100 29 20 6 4 4 2 6 5 3 13 9 8 5 4 4 10 5 5 30 9 11 12 12 5 8 8 4 29 5 1 16 7 2 28 8 6 3 1 1 11 11 1...
output:
763947475 5 36 10080 5 1638 0 13260 165 249143859 5542680 630775223 5 1 56 534529540 293930 27971953...
result:
ok 100 lines
Test #6:
score: 5
Accepted
time: 62ms
memory: 47380kb
input:
100 5 5 5 26 22 4 19 17 16 25 17 8 31 2 2 28 21 12 15 3 1 31 8 2 22 1 1 15 3 2 3 2 2 25 17 3 15 3 3 ...
output:
1 957177681 2720 337431182 462027062 923233078 1485800 116294070 482563003 3863080 3 549208528 43459...
result:
ok 100 lines
Test #7:
score: 5
Accepted
time: 66ms
memory: 47380kb
input:
10 474 293 237 481 396 187 364 43 45 741 78 8 158 53 30 463 445 433 120 110 62 503 52 16 360 318 32 ...
output:
323352985 63241071 0 222507962 478641805 854383331 893261429 747110781 699961226 252997894
result:
ok 10 lines
Test #8:
score: 5
Accepted
time: 81ms
memory: 47380kb
input:
10 641 326 203 15 3 2 153 20 25 288 240 91 499 105 31 732 581 299 994 253 153 352 106 28 62 13 10 93...
output:
919680035 3863080 0 724023677 581680580 794343262 840693979 288065703 184728173 158286453
result:
ok 10 lines
Test #9:
score: 5
Accepted
time: 94ms
memory: 47384kb
input:
10 543 141 147 663 293 26 45 31 12 69 18 22 348 49 36 37 5 4 767 411 318 421 193 84 965 44 46 398 30...
output:
0 536162423 542866247 0 356102686 284316141 577945523 655525950 0 0
result:
ok 10 lines
Test #10:
score: 5
Accepted
time: 75ms
memory: 47384kb
input:
10 999 387 390 189 157 55 324 281 150 954 62 8 514 147 89 331 236 171 150 46 15 979 216 59 682 175 1...
output:
0 657224842 866062375 612350269 797998629 965804890 33283886 370426989 0 753780884
result:
ok 10 lines
Test #11:
score: 5
Accepted
time: 76ms
memory: 47380kb
input:
10 284 110 71 343 327 228 890 627 348 756 63 8 919 31 5 542 69 21 109 15 6 424 252 155 899 5 1 192 1...
output:
939661935 7427866 845407531 565632090 584793981 721121700 999456680 490287152 790372676 0
result:
ok 10 lines
Test #12:
score: 5
Accepted
time: 84ms
memory: 47380kb
input:
10 957 341 186 433 199 51 760 510 73 406 179 137 739 207 230 74 43 43 881 518 106 118 100 29 724 475...
output:
475101795 640352890 452627676 917987052 0 220718056 847304648 569168532 840548600 367170930
result:
ok 10 lines
Test #13:
score: 5
Accepted
time: 88ms
memory: 47380kb
input:
10000 948520 153123 37633 978977 610707 430315 861510 89319 84311 89854 76753 23361 539648 26973 539...
output:
224882239 78243119 752768981 133670970 823837837 861202414 172458352 917749445 141351091 428891672 1...
result:
ok 10000 lines
Test #14:
score: 5
Accepted
time: 90ms
memory: 47380kb
input:
10000 776217 468283 394226 679502 396921 440333 336294 175951 21262 158362 85737 87647 786586 679022...
output:
593235084 0 693263768 0 239343520 75293794 855075166 448580350 971747286 415188727 0 453115359 16674...
result:
ok 10000 lines
Test #15:
score: 5
Accepted
time: 88ms
memory: 47384kb
input:
10000 727020 72982 84798 511326 476765 238661 768301 198556 241391 42904 770 3 225143 21785 19973 71...
output:
0 264209582 0 365827860 338776996 0 643364371 0 923750084 514419494 803184187 996127244 18795969 819...
result:
ok 10000 lines
Test #16:
score: 5
Accepted
time: 102ms
memory: 47380kb
input:
10000 349236 250424 6551 245300 155779 53345 718003 538775 455477 554195 3258 1970 864269 350613 163...
output:
614690665 48068909 961727825 116922077 937665053 545463810 159985171 40051945 163855553 525905370 75...
result:
ok 10000 lines
Test #17:
score: 5
Accepted
time: 120ms
memory: 47380kb
input:
10000 130797 50408 54584 589075 456571 10806 78159 33427 38224 303639 7008 8635 585821 448649 100079...
output:
0 862178676 0 0 647286860 488363651 887107171 45701820 505945040 171439785 533367105 321658620 28991...
result:
ok 10000 lines
Test #18:
score: 5
Accepted
time: 90ms
memory: 47380kb
input:
10000 693060 190134 160913 997339 460961 184242 899251 525330 137457 513519 345024 295373 352825 155...
output:
285831846 259325823 603184339 400765664 326888470 292981576 579043448 572924932 83311047 662899396 1...
result:
ok 10000 lines
Test #19:
score: 5
Accepted
time: 87ms
memory: 47380kb
input:
10000 933167 891532 704848 80961 67286 35337 240488 174845 21388 451269 212850 49163 948517 31409 36...
output:
31241498 734172905 515809396 744766113 0 934513159 814225104 928984552 459018579 830020604 141239706...
result:
ok 10000 lines
Test #20:
score: 5
Accepted
time: 101ms
memory: 47380kb
input:
10000 61939 9116 2096 150659 75224 41401 13674 12474 10722 152304 47286 14033 319787 185775 135285 8...
output:
494879849 236192375 710885048 18162371 183133441 806117830 287024099 378052720 899612100 538326070 7...
result:
ok 10000 lines