QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#291094 | #4104. 排列计数 | MoRanSky | 100 ✓ | 144ms | 15644kb | C++23 | 857b | 2023-12-26 04:49:45 | 2023-12-26 04:49:46 |
Judging History
answer
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1000001, P = 1e9 + 7;
typedef long long LL;
int n, m, fact[N], infact[N];
int f[N];
int power (int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = (LL)res * a % P;
a = (LL)a * a % P;
b >>= 1;
}
return res;
}
int C(int a, int b) {
return (LL)fact[a] * infact[b] % P * infact[a - b] % P;
}
int main() {
fact[0] = infact[0] = 1;
for (int i = 1; i < N; i++) fact[i] = (LL)fact[i - 1] * i % P;
infact[N - 1] = power(fact[N - 1], P - 2);
for (int i = N - 2; i; i--) infact[i] = (LL)infact[i + 1] * (i + 1) % P;
f[0] = f[2] = 1;
for (int i = 3; i < N; i++)
f[i] = (LL)(i - 1) * (f[i - 1] + f[i - 2]) % P;
int T; scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
printf("%d\n", (LL)C(n, m) * f[n - m] % P);
}
return 0;
}
详细
Test #1:
score: 5
Accepted
time: 17ms
memory: 15644kb
input:
1000 1 1 7 0 2 2 5 1 2 1 3 0 2 1 1 1 3 0 1 0 6 2 4 1 4 0 2 0 6 2 5 1 5 0 5 2 3 1 4 0 7 0 2 1 4 0 1 0 2 1 2 1 1 1 5 1 4 2 3 0 3 2 7 1 7 0 8 0 1 0 7 1 2 2 6 2 3 1 6 1 5 0 7 0 2 0 3 2 1 0 2 2 5 1 6 2 5 1 7 0 4 1 7 1 2 1 7 0 8 1 7 0 6 1 1 0 7 2 5 0 3 1 5 2 4 0 2 2 1 1 4 0 4 2 5 2 6 1 5 0 1 0 6 2 4 2 8 0...
output:
1 1854 1 45 0 2 0 1 2 0 135 8 9 1 135 45 44 20 3 9 1854 0 9 0 0 0 1 45 6 2 0 1855 1854 14833 0 1855 1 135 3 264 44 1854 1 0 0 1 45 135 45 1854 8 1855 0 1854 14832 1854 264 0 924 44 3 20 9 1 1 9 6 20 264 44 0 135 6 14833 1 45 3 135 1854 0 1 135 1 1854 7420 7420 924 1 924 20 0 1 1855 3 7420 1 924 45 0...
result:
ok 1000 lines
Test #2:
score: 5
Accepted
time: 17ms
memory: 15640kb
input:
1000 1 0 1 1 3 3 2 0 8 8 7 3 1 1 8 1 7 2 7 6 3 0 5 5 6 6 2 0 1 1 8 5 6 4 7 7 4 0 1 0 6 6 6 5 3 2 1 0 6 1 8 4 7 3 6 5 7 5 4 4 7 5 2 0 8 5 2 2 3 0 5 4 1 1 3 2 3 0 6 1 3 3 6 5 8 4 5 5 4 2 3 1 1 1 2 0 7 7 3 1 6 5 6 5 1 0 5 1 8 4 8 6 4 4 1 0 6 3 8 1 7 6 7 6 8 1 7 3 3 0 8 2 7 5 4 4 6 4 3 1 2 0 7 7 2 2 8 3...
output:
0 1 1 1 1 315 1 14832 924 0 2 1 1 1 1 112 15 1 9 0 1 0 0 0 264 630 315 0 21 1 21 1 112 1 2 0 1 0 2 264 1 0 630 1 6 3 1 1 1 3 0 0 0 45 630 28 1 0 40 14832 0 0 14832 315 2 7420 21 1 15 3 1 1 1 2464 0 0 0 630 44 7420 9 1 10 1854 0 924 1 0 0 10 1 0 0 265 264 924 1 0 924 135 1 315 45 9 135 0 40 1 45 0 6 ...
result:
ok 1000 lines
Test #3:
score: 5
Accepted
time: 16ms
memory: 15640kb
input:
1000 4 3 6 2 7 1 2 1 1 1 6 1 3 0 3 0 6 4 1 1 3 3 1 0 3 0 6 6 8 8 6 0 1 1 5 0 1 0 2 0 7 6 6 1 6 0 3 0 6 1 2 2 8 8 3 1 5 0 8 7 6 5 2 1 4 3 1 1 8 1 6 0 3 3 3 0 6 2 1 1 3 1 8 3 1 0 2 2 3 0 8 8 1 1 2 2 3 1 1 0 4 2 7 3 4 0 5 3 4 1 4 4 5 3 4 3 8 5 6 4 6 5 4 0 8 6 7 2 8 1 7 3 5 3 6 3 2 0 4 3 6 2 3 2 4 4 4 1...
output:
0 135 1855 0 1 264 2 2 15 1 1 0 2 1 1 265 1 44 0 1 0 264 265 2 264 1 1 3 44 0 0 0 0 1 14832 265 1 2 135 1 3 2464 0 1 2 1 1 1 3 0 6 315 9 10 8 1 10 0 112 15 0 9 28 924 14832 315 10 40 1 0 135 0 1 8 3 315 0 1 1 1 0 1 0 1 6 630 0 112 7420 1 6 44 0 8 315 1 7420 1 15 0 9 0 0 1 0 0 1 630 15 112 15 1 1 15 ...
result:
ok 1000 lines
Test #4:
score: 5
Accepted
time: 16ms
memory: 15640kb
input:
1000 2 0 10 2 2 2 10 6 9 7 5 4 8 8 4 4 5 1 9 8 7 5 5 2 12 11 12 8 10 6 4 3 12 5 10 10 5 2 10 4 4 1 5 4 4 4 1 1 1 0 7 7 8 4 3 2 2 0 3 3 4 1 8 8 3 2 10 4 8 6 6 0 1 1 11 9 1 1 11 10 10 9 6 4 2 0 3 1 5 4 11 9 3 0 4 2 7 3 3 1 1 1 12 0 2 0 9 9 7 7 7 1 9 3 6 6 5 0 3 1 4 2 8 7 8 4 2 1 8 0 9 1 2 1 11 11 12 1...
output:
1 667485 1 1890 36 0 1 1 45 0 21 20 0 4455 1890 0 1468368 1 20 55650 8 0 1 1 0 1 630 0 1 1 8 1 0 55650 28 265 1 55 1 0 0 15 1 3 0 55 2 6 315 3 1 176214841 1 1 1 1855 22260 1 44 3 6 0 630 0 14833 133497 0 1 176214840 0 1890 2 14832 1 10 44 1 667485 1134 20 0 0 0 0 315 0 1 0 1 6 1 315 3 45 2 6 0 1 44 ...
result:
ok 1000 lines
Test #5:
score: 5
Accepted
time: 8ms
memory: 15456kb
input:
1000 12 7 2 1 9 6 8 4 1 0 2 1 1 1 1 0 2 0 5 0 2 0 8 0 8 6 10 1 11 11 5 4 2 0 10 10 4 0 1 1 9 6 11 2 9 1 11 5 7 4 7 7 7 2 3 3 6 0 10 5 5 1 5 1 2 1 6 1 8 8 10 0 1 1 9 4 11 5 1 1 9 6 11 0 2 2 3 2 10 2 6 4 5 5 6 5 2 0 12 7 1 0 1 1 7 6 8 0 5 0 1 0 12 4 11 6 1 1 4 1 10 4 4 0 6 2 9 7 8 5 3 2 11 0 12 8 6 3 ...
output:
34848 0 168 630 0 0 1 0 1 44 1 14833 28 1334960 1 0 1 1 9 1 168 7342280 133497 122430 70 1 924 1 265 11088 45 45 0 264 1 1334961 1 5544 122430 1 168 14684570 1 0 667485 15 1 0 1 34848 0 1 0 14833 44 0 7342335 20328 1 8 55650 9 135 36 112 0 14684570 4455 40 7342335 34848 40 176214840 2464 1334960 15 ...
result:
ok 1000 lines
Test #6:
score: 5
Accepted
time: 16ms
memory: 15572kb
input:
1000 1 0 1 0 3 0 6 0 8 1 3 3 9 9 1 1 7 1 8 6 4 3 10 5 3 2 4 2 11 8 5 5 11 9 1 0 10 0 11 2 12 8 9 0 2 0 3 0 1 1 3 3 6 3 1 0 2 0 8 4 10 5 6 2 3 1 2 1 11 9 1 1 5 5 7 6 4 2 2 2 3 1 11 8 1 1 2 2 2 1 5 4 11 4 12 11 4 2 5 2 4 0 12 1 3 1 3 3 7 4 6 5 3 1 4 3 1 1 3 3 2 0 7 5 12 11 6 3 2 2 8 2 3 2 4 0 7 1 3 1 ...
output:
0 0 2 265 14832 1 1 1 1855 28 0 11088 0 6 330 1 55 0 1334961 7342280 4455 133496 1 2 1 1 40 0 1 630 11088 135 3 0 55 1 1 0 6 1 3 330 1 1 0 0 611820 0 6 20 9 176214840 3 1 70 0 3 0 1 1 1 21 0 40 1 7420 0 9 1855 3 40 7420 0 1 1 0 34848 1 1 1334960 0 1 1854 36 0 0 21 0 20 244860 7342335 1 70 40 0 21 22...
result:
ok 1000 lines
Test #7:
score: 5
Accepted
time: 16ms
memory: 15636kb
input:
1000 29 25 47 32 76 8 99 12 78 26 40 15 60 54 92 9 16 16 15 5 9 5 60 15 78 63 24 6 50 24 29 7 88 56 64 32 4 1 53 47 51 35 14 14 98 86 11 7 26 3 86 86 80 7 87 81 25 10 52 32 30 28 58 51 21 6 1 0 1 0 91 66 48 22 1 1 40 4 27 26 57 24 10 1 3 2 8 2 81 52 42 9 31 21 72 43 86 28 24 0 91 62 27 21 71 44 37 4...
output:
213759 404403496 703037972 260916130 8049381 734267840 266922809 224688083 1 8887855 1134 847474204 615885227 426676945 354737956 185247475 989488344 730873071 8 83732158 373572160 1 17286870 2970 275294240 1 734817995 820064504 963233036 876400115 435 449755253 227057625 0 0 775215116 420332799 1 5...
result:
ok 1000 lines
Test #8:
score: 5
Accepted
time: 12ms
memory: 15528kb
input:
1000 36 26 8 7 88 38 64 26 39 35 11 6 23 22 83 62 51 7 96 85 66 12 92 15 15 13 8 7 33 27 16 9 40 22 65 48 9 6 34 9 69 33 62 6 93 22 30 11 34 13 52 52 33 5 29 19 99 97 97 10 73 58 81 62 49 42 28 15 50 19 21 3 87 35 85 31 99 11 90 43 1 0 57 54 13 2 30 11 24 6 75 28 99 17 88 40 11 0 39 17 37 9 37 36 18...
output:
537097313 0 621397312 30219349 740259 20328 0 118425551 428900821 750817393 199220141 238615422 105 0 293505520 21209760 292055390 18028066 168 156481384 824120310 357333025 20474909 751882367 143737826 1 325950354 281992437 4851 37563485 859517255 445824006 259681623 886407482 760549291 247299181 6...
result:
ok 1000 lines
Test #9:
score: 5
Accepted
time: 12ms
memory: 15608kb
input:
1000 42 21 69 20 32 13 88 29 40 20 98 52 17 0 45 43 90 30 85 39 66 44 32 28 4 3 3 3 91 81 18 0 67 53 51 1 57 44 90 75 70 4 17 15 19 8 52 25 57 51 97 5 13 8 9 6 25 18 44 34 68 20 20 0 48 23 21 8 47 45 85 24 85 38 21 21 38 24 89 32 21 17 35 23 66 4 23 14 86 46 75 45 14 4 55 32 63 17 13 1 90 12 50 10 1...
output:
78048433 514311354 883764768 867714930 845559995 314418696 91363714 990 62552207 414691550 292058342 323640 0 1 981537275 644546846 925175141 969323655 576832904 184008488 812849236 136 889161977 814069021 616386717 101777003 56628 168 891217800 6428991 615419275 927799753 815793173 450469609 1081 8...
result:
ok 1000 lines
Test #10:
score: 5
Accepted
time: 17ms
memory: 15640kb
input:
1000 180 180 573 558 367 150 254 239 580 383 844 95 790 658 390 245 796 724 661 175 409 249 451 316 541 109 593 193 616 368 711 704 485 112 991 534 908 895 97 46 806 283 583 252 164 21 914 324 144 51 434 219 113 56 569 299 849 208 583 162 394 296 150 86 547 299 110 17 895 195 761 23 701 211 424 78 4...
output:
1 999700925 608823314 895755333 500167130 424784199 640850472 880036566 409295595 803068101 897760950 960453132 917167739 836439476 656819252 317253366 724117800 971875168 77156714 235181479 199755274 339277428 683560698 615573972 710011182 942431814 125504760 413835096 497793974 18437071 84487551 7...
result:
ok 1000 lines
Test #11:
score: 5
Accepted
time: 16ms
memory: 15640kb
input:
1000 401 143 892 462 709 247 769 11 943 857 341 238 418 71 122 53 589 164 585 478 307 234 538 89 212 95 718 142 473 358 776 634 571 279 543 121 275 175 796 447 642 305 345 169 433 209 175 14 401 324 414 41 436 277 192 168 953 328 869 116 867 456 503 250 337 156 22 12 878 685 684 356 690 373 290 234 ...
output:
735805484 876488170 656880547 780413176 878033995 775754310 993064177 303737301 979656073 753945341 204212750 23687095 631173379 311433737 13731742 930810550 273370059 194757709 334291601 822891532 721253156 459584016 793898970 64142809 788363814 653231858 76237204 24884186 528022834 130636949 61362...
result:
ok 1000 lines
Test #12:
score: 5
Accepted
time: 13ms
memory: 15596kb
input:
1000 186 49 742 283 150 144 190 83 286 183 537 456 297 182 162 116 274 162 991 393 449 148 371 42 247 194 727 465 181 72 363 110 188 63 937 468 589 247 914 171 617 22 230 43 89 56 655 629 751 41 749 704 218 77 42 25 932 537 742 87 751 541 131 29 203 193 210 204 960 816 227 138 921 465 455 213 630 21...
output:
920444202 199044648 705165609 141082647 806255914 731329451 841540048 848862331 374013922 503802974 661404887 559202139 708782996 602569528 528962496 625484524 14115792 463083667 262832123 828652400 44522792 646169668 378594657 282953717 10337621 324275056 515136915 501602172 535606852 357141852 596...
result:
ok 1000 lines
Test #13:
score: 5
Accepted
time: 84ms
memory: 15596kb
input:
500000 557 220 580 19 27 13 447 360 23 4 25 22 820 211 884 851 586 292 249 23 410 225 656 344 125 57 267 143 500 150 810 786 592 235 711 598 594 4 483 332 307 132 86 83 452 424 434 45 15 6 383 278 907 869 687 682 355 150 299 263 662 594 259 24 479 399 936 407 950 98 308 58 660 210 24 3 330 213 533 5...
output:
218990033 596599662 668114373 494984695 783337328 4600 418775848 498879222 767367101 437914601 72096482 206164805 350937855 562828041 72490284 803447927 747819358 263084546 127479963 141686953 459819010 204680 100443024 130550103 668147480 549129846 316682892 302952495 523592595 221187376 453798522 ...
result:
ok 500000 lines
Test #14:
score: 5
Accepted
time: 76ms
memory: 15592kb
input:
500000 179 138 970 4 4 3 208 131 220 208 501 172 604 413 884 880 325 275 492 421 272 165 934 520 6 1 372 10 721 478 639 158 48 1 7 7 637 622 774 295 338 23 421 332 206 21 123 54 452 305 820 156 316 77 951 527 839 569 798 201 261 61 657 26 25 12 770 178 683 518 538 313 749 507 889 699 198 172 688 302...
output:
777368907 79546827 0 98404764 579270788 891514755 248106363 451458920 798114254 282205842 278208425 842136676 264 287943125 335174261 942103259 459215443 1 319374604 566471917 834185044 172107805 414939504 191846071 671630616 646045083 684968506 467735183 296369708 349094578 104059265 588415475 4008...
result:
ok 500000 lines
Test #15:
score: 5
Accepted
time: 139ms
memory: 15592kb
input:
500000 323382 286126 582651 493887 677066 227600 227845 205199 635909 229638 236822 171983 541112 145935 420255 206672 866356 816331 676947 105719 992971 206765 306336 144563 789900 142081 672826 432996 800074 493922 813264 533552 433620 268749 733907 649212 451261 194482 498613 465691 594196 502801...
output:
110437176 4951163 972861320 96779444 633400475 317851717 391304620 12499748 784937392 129447329 455957123 970125412 310217982 165600641 185931379 989305806 146407485 792718891 187841249 26483357 984782348 516867039 217882987 107154106 380327788 588777702 739936212 606102954 550966402 418764067 92149...
result:
ok 500000 lines
Test #16:
score: 5
Accepted
time: 139ms
memory: 15612kb
input:
500000 574428 178046 449385 184112 300899 175644 243886 15130 433377 302818 885834 41658 574760 25125 970543 44845 675847 420960 296205 242937 872721 400243 512534 370380 697302 194996 48635 9198 221606 111555 44332 18719 920788 607993 450331 155097 141872 1733 537336 235156 924555 573494 656053 429...
output:
544527194 470638914 154284564 70625842 177859636 587007219 812846404 234960984 695904736 3575271 578627344 552596099 101233874 452820298 310623275 565378870 879717122 440669610 114604483 986867620 204044945 965229198 719583449 341074692 940070976 844418500 643036634 217107346 356360921 156694100 579...
result:
ok 500000 lines
Test #17:
score: 5
Accepted
time: 125ms
memory: 15568kb
input:
500000 414742 305965 575019 61929 920977 55690 643179 524714 497618 177692 639378 210701 676972 494501 242771 46198 913263 821671 375132 95216 909739 423536 930976 578387 540531 248207 375760 131643 412439 14949 762141 53878 108840 69781 818807 690274 358520 103329 916559 387686 681110 438840 965527...
output:
876455198 260471707 764621865 7409021 559993630 681336885 140794445 800147566 764421198 270943548 87701072 808966712 712320367 91482903 336926999 673789528 157226406 196979939 357551398 595729805 143898681 164605945 896405675 729084018 44103036 614197617 261618555 65547348 285980537 797781551 789906...
result:
ok 500000 lines
Test #18:
score: 5
Accepted
time: 134ms
memory: 15456kb
input:
500000 622244 395 607873 135586 300306 64036 808828 657263 90199 73912 582767 104494 456452 198511 273098 271314 896106 804956 772159 261471 510554 88247 58367 22709 313701 146098 794234 686179 714716 662714 986593 274552 945169 443375 650087 188323 977427 236197 108346 97145 367285 26658 405774 217...
output:
724443109 375168938 268276635 158760821 747224299 364697313 623992202 920302125 964027368 450620422 860941412 672923871 9461784 827480381 25709732 738172268 916962714 230950784 127017621 389029893 665823331 771422765 749790292 109147949 595912977 323099100 686539903 832323190 971204821 873689363 403...
result:
ok 500000 lines
Test #19:
score: 5
Accepted
time: 138ms
memory: 15560kb
input:
500000 403974 292398 77227 1343 425895 355146 398753 220227 344368 23836 719455 102136 691184 488191 484438 378528 652473 300412 201270 20107 719516 192140 44209 8770 498219 297341 478199 338770 375093 29961 746938 242440 303501 294962 3690 1472 33667 16991 770489 51598 164199 155728 287640 10121 67...
output:
761625407 393047775 47002345 691701168 317256014 370100816 5256425 568980364 122494169 237698522 791573422 129337054 104632705 920923741 221941403 520403917 584062704 588104302 548767119 581227595 233220452 166182794 464140792 587191692 163940357 282815181 924001170 66931577 403217917 98201327 11811...
result:
ok 500000 lines
Test #20:
score: 5
Accepted
time: 144ms
memory: 15596kb
input:
500000 230525 61697 696936 258850 939217 837089 674458 99267 304476 290510 312419 159201 313456 22842 98741 14695 662492 147387 407553 195547 783155 100410 238903 90551 854340 793575 810888 330623 252130 177332 408806 287642 745885 367308 456706 378782 153478 112666 294221 86663 237678 150739 736054...
output:
284491620 225185755 126175631 375425138 142442279 770089453 378102232 925325764 151656134 482801529 884977766 925140210 692365592 358504613 80482650 297738157 66617146 151098743 441549615 964297450 643153674 300144815 920173950 106632025 164802245 891999763 274921024 142618290 348683013 489083674 18...
result:
ok 500000 lines