QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#315935#6157. 组合数问题luyiming12345 23ms30320kbC++231.5kb2024-01-27 16:31:352024-01-27 16:31:35

Judging History

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

  • [2024-01-27 16:31:35]
  • 评测
  • 测评结果:45
  • 用时:23ms
  • 内存:30320kb
  • [2024-01-27 16:31:35]
  • 提交

answer

# include <bits/stdc++.h>
# define int long long
using namespace std;
const int M = 2005; 
using i64 = long long; 
i64 n, x, mod; int m; 
i64 a[M], S2[M][M], fac[M], xjm[M], p1x[M]; 
i64 qpow(i64 x, i64 p = mod - 2ll)
{
    i64 ans = 1ll; 
    while(p) 
    {
        if(p & 1) ans = ans * x % mod; 
        x = x * x % mod, p >>= 1; 
    }
    return ans; 
}

void Add(i64 &x, i64 y) { x = (x + y) % mod; if(x < 0) x += mod; return; }
void Init(int n = M - 5)
{
    S2[0][0] = 1, fac[0] = 1ll, xjm[0] = 1ll; 
    for(int k = 1; k <= min(n, m); k++) {xjm[k] = xjm[k - 1] * (::n - k + 1ll) % mod; }
    p1x[min(::n, m)] = qpow(1ll + x, ::n - min(::n, m)); 
    for(int i = min(::n, m) - 1; i >= 0; i--) p1x[i] = p1x[i + 1] * (1ll + x) % mod; 
    for(int i = 1; i <= n; i++) 
    {
        for(int j = 1; j <= i; j++) 
        {
            S2[i][j] = (S2[i - 1][j - 1] + j * S2[i - 1][j] % mod) % mod; 
        }
        fac[i] = fac[i - 1] * 1ll * i % mod; 
    }
    return; 
}
signed main(void)
{
    scanf("%lld%lld%lld%lld", &n, &x, &mod, &m); 
    Init(); 
    for(int i = 0; i <= m; i++) scanf("%lld", &a[i]); 
    i64 Ans = 0; 
    for(int i = 0; i <= m; i++)
    {
        i64 px = 1ll; 
        for(int j = 0; j <= i; j++, px = px * x % mod)
        {
            assert(px == 1ll); 
            Add(Ans, a[i] * xjm[j] % mod * px % mod * p1x[j] % mod * S2[i][j] % mod); 
        }
    }
    printf("%lld\n", Ans); 
    return 0; 
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

1000 643189585 831941236 1000
621444125 324708497 619770455 112615814 800909697 461794889 380815971 872773343 314541774 472606930 636420887 783552328 794270098 539204140 23007446 139105268 406306323 866123427 218553206 804461683 30473072 117201808 568299563 477252115 324883663 342559946 1371621 5042...

output:


result:


Test #2:

score: 0
Runtime Error

input:

1000 503195138 513597392 1000
722484910 931359038 343065489 981840058 521519661 226445599 530176715 770414408 102322476 673203111 507109164 694874631 741867637 279337383 424160545 294330405 82544373 48857855 815232637 669279005 52910855 214526933 849319059 181639810 172299266 889272850 596357056 666...

output:


result:


Test #3:

score: 0
Runtime Error

input:

1000 906011316 702916476 1000
426378198 448666835 928428034 473805142 373675324 45261623 502895126 736498316 231472510 191865836 242418084 544276235 444104055 477445639 356224464 953908838 306690394 584707561 294817458 752251380 852722174 469468566 503286490 871710527 705395858 404720545 938309838 1...

output:


result:


Test #4:

score: 5
Accepted
time: 12ms
memory: 29088kb

input:

100000 677812091 277 0
807583683

output:

71

result:

ok 1 number(s): "71"

Test #5:

score: 5
Accepted
time: 21ms
memory: 29092kb

input:

100000 981163973 25889 0
973863137

output:

12731

result:

ok 1 number(s): "12731"

Test #6:

score: 5
Accepted
time: 12ms
memory: 30320kb

input:

100000 835568175 7401731 0
906329707

output:

3064835

result:

ok 1 number(s): "3064835"

Test #7:

score: 5
Accepted
time: 16ms
memory: 29176kb

input:

1000000000 790947092 627519428 0
60710186

output:

272191242

result:

ok 1 number(s): "272191242"

Test #8:

score: 5
Accepted
time: 10ms
memory: 29128kb

input:

1000000000 650690291 731646919 0
877581470

output:

15529275

result:

ok 1 number(s): "15529275"

Test #9:

score: 0
Runtime Error

input:

1000000000 797047750 618934290 3
961481438 877843421 701730260 298899

output:


result:


Test #10:

score: 0
Runtime Error

input:

1000000000 864318301 584940599 3
633737140 774981490 625591778 241085537

output:


result:


Test #11:

score: 0
Runtime Error

input:

1000000000 848364348 882312605 4
170103640 631151726 271592928 185866004 334973069

output:


result:


Test #12:

score: 0
Runtime Error

input:

1000000000 632003439 731204527 5
528931262 239172080 749520006 43675943 695916953 6562492

output:


result:


Test #13:

score: 5
Accepted
time: 15ms
memory: 29100kb

input:

1000000000 1 766455601 1000
558055814 109246028 38835513 947196933 242586123 147273834 256441677 15594213 98941360 755103145 463954471 169688646 98806912 642927659 621211739 713955885 391698389 163712447 588561728 647301220 39465644 800390415 324148500 871577287 613523228 342178732 36750461 26345791...

output:

657791066

result:

ok 1 number(s): "657791066"

Test #14:

score: 5
Accepted
time: 23ms
memory: 29012kb

input:

1000000000 1 873712850 1000
278171983 164635568 206054551 341466272 947345526 592513430 491563677 341146136 935528892 632574736 565810285 515879482 994979438 164263680 189449944 440718937 492084059 497263419 573679235 699086245 659495381 975774703 586571408 481989509 489369682 258500183 253174606 94...

output:

357599008

result:

ok 1 number(s): "357599008"

Test #15:

score: 5
Accepted
time: 19ms
memory: 29208kb

input:

1000000000 1 801809934 1000
326406661 169791972 761656767 15280008 186815446 186117411 265403224 308467755 392051233 725260841 341791121 418439521 777844152 419969954 730027819 343615863 568299464 475588222 277121423 761476244 202455418 960116443 484950749 866814884 28710946 434807477 996165424 7697...

output:

762344818

result:

ok 1 number(s): "762344818"

Test #16:

score: 5
Accepted
time: 23ms
memory: 29008kb

input:

1000000000 1 605325981 1000
300766868 885995664 277533356 168649814 892768488 291744630 646838712 856019873 59320837 572912057 690027481 880187770 374756433 903619161 122904149 844522459 95811969 772786363 239314288 992117811 387289152 145852010 767518940 830315681 766920764 440439657 93192393 76897...

output:

58895801

result:

ok 1 number(s): "58895801"

Test #17:

score: 0
Runtime Error

input:

1000000000 957733823 809081300 1000
533363221 638929575 443006622 286508611 691905309 228596664 175904171 410178708 451046889 127797916 415935615 570618723 800660185 563213999 903523847 668436995 933625911 861427774 755608174 362042286 314119712 895203661 417507948 153273866 167248092 956338547 3406...

output:


result:


Test #18:

score: 0
Runtime Error

input:

1000000000 610363186 847371151 1000
665297781 786213968 431288588 909998294 800117192 27065236 692646918 881650665 265579161 44215444 99633849 582605709 402479473 972764887 466468004 538706661 251804078 454620935 67255325 783865759 693395798 583174943 305918899 503101381 981809034 107696 736321655 4...

output:


result:


Test #19:

score: 0
Runtime Error

input:

1000000000 534756891 543527658 1000
702340808 598102723 853329752 572034620 975329351 617733109 230679944 829852779 503128018 355746866 443120420 51627950 127579068 106567561 79644532 703345646 306545813 302226744 726078059 118130342 68034745 998675817 12288173 368910305 490224052 374647055 27100878...

output:


result:


Test #20:

score: 0
Runtime Error

input:

1000000000 909107105 657355356 1000
90722426 58432815 680303429 656802978 821714069 81032229 404049008 508394045 815033128 537356713 111806335 80898026 295991237 78868790 550351734 549534112 766404863 359634541 285022912 417815753 284604425 900505912 411877558 12589604 66352005 634143645 90909857 16...

output:


result: