QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741537#8351. Ruin the legenddaydreamwarrior100 ✓47ms210104kbC++141.9kb2024-11-13 14:34:322024-11-13 14:34:32

Judging History

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

  • [2024-11-13 14:34:32]
  • 评测
  • 测评结果:100
  • 用时:47ms
  • 内存:210104kb
  • [2024-11-13 14:34:32]
  • 提交

answer

#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

struct{char buf[1<<20],*l=buf,*r=l;
operator char(){return l==r&&(r=(l=buf)+fread(buf,1,1<<20,stdin),l==r)?-1:*l++;}
template<typename T>operator T(){
    T x=0;char f=0,c;
    do if((c=*this)=='-')f=1;while(c<'0'||c>'9');
    while(c>='0'&&c<='9')x=x*10+(c^48),c=*this;
    return f?-x:x;
}}in;void out(char c){putchar(c);}
template<typename T>void out(T x){
    static signed stk[39],tp;
    if(x<0)out('-'),x=-x;
    do stk[tp++]=x%10;while(x/=10);
    while(tp)putchar(stk[--tp]^48);
}template<typename T,typename...Args>
void out(T x,Args...args){out(x);out(args...);}

typedef long long ll;
const int N = 5005,M = 1000005,mod = 998244353;
vector<int> c[M];
int a[N];
int n,K;

int f[N][N][2];
int g[N],gg[N];
int fac[N];

int main(){
    n = in,K = in;

    fac[0] = 1;
    for(int k=1;k<=n;k++)
        fac[k] = 1ull*fac[k-1]*k%mod;

    for(int k=1;k<=n;k++){
        a[k] = in;
        c[a[k]%K].push_back(a[k]);
    }
    f[1][0][0] = 1;
    for(int k=2;k<=n;k++)
        for(int j=0;j<k;j++){
            f[k][j][0] = (f[k-1][j][0]+f[k-1][j][1])%mod;
            f[k][j+1][1] = (f[k-1][j][0]*2ull+f[k-1][j][1])%mod;
        }
    g[0] = 1;
    auto add = [](int v){
        memset(gg,0,sizeof(int)*n);
        for(int k=0;k<v;k++)
            for(int j=k;j<n;j++)
                gg[j] = (gg[j]+1ull*g[j-k]*(f[v][k][0]+f[v][k][1]))%mod;
        for(int k=0;k<n;k++)
            g[k] = gg[k];
    };
    for(int k=0;k<K;k++){
        if(c[k].empty())
            continue;
        int i = 1;
        for(int j=1;j<c[k].size();j++,i++)
            if(c[k][j-1]+K!=c[k][j]){
                add(i);
                i = 0;
            }
        add(i);
    }
    int ans = 0;
    for(int k=0;k<n;k++)
        ans = (ans+1ull*mod*mod+((k&1)?-1ull:1ull)*g[k]*fac[n-k])%mod;
    out(ans);
    return 0;
}

详细

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 6ms
memory: 30240kb

input:

10 361915
1186738 1548653 1910568 2272483 2634398 2996313 4082058 4443973 4805888 5167803

output:

605624

result:

ok 1 number(s): "605624"

Test #2:

score: 20
Accepted
time: 4ms
memory: 29064kb

input:

10 503576
1412863 3427167 3694544 3930743 4198120 4434319 4937895 5441471 5945047 6212424

output:

919056

result:

ok 1 number(s): "919056"

Subtask #2:

score: 30
Accepted

Test #3:

score: 30
Accepted
time: 4ms
memory: 44628kb

input:

400 246137
1245623 1491760 1737897 1930990 1984034 2177127 2230171 2423264 2476308 2669401 2722445 2915538 2968582 3161675 3214719 3407812 3460856 3653949 3706993 3900086 3953130 4146223 4199267 4392360 4445404 4638497 4691541 4884634 4937678 5130771 5183815 5376908 5429952 5623045 5676089 5869182 5...

output:

672078497

result:

ok 1 number(s): "672078497"

Test #4:

score: 30
Accepted
time: 7ms
memory: 44652kb

input:

400 595353
60469 655822 1251175 1846528 1994258 2441881 2589611 3037234 3184964 3576288 3632587 3755516 3780317 4171641 4227940 4350869 4375670 4766994 4823293 4946222 4971023 5362347 5418646 5541575 5566376 5702177 5957700 6013999 6136928 6161729 6297530 6553053 6609352 6732281 6757082 6892883 7148...

output:

955108635

result:

ok 1 number(s): "955108635"

Test #5:

score: 30
Accepted
time: 4ms
memory: 43004kb

input:

400 599588
698120 881310 894243 953566 1297708 1300366 1314706 1463444 1480898 1493831 1553154 1563240 1603860 1658458 1897296 1899954 1914294 2063032 2080486 2093419 2104932 2152742 2162828 2203448 2234734 2258046 2334676 2496884 2499542 2513882 2662620 2680074 2693007 2704520 2752330 2762416 28030...

output:

208730170

result:

ok 1 number(s): "208730170"

Subtask #3:

score: 20
Accepted

Test #6:

score: 20
Accepted
time: 11ms
memory: 67696kb

input:

1000 567438
1434354 2001792 2569230 2944075 3136668 3392405 3511513 3704106 3959843 4078951 4271544 4527281 4646389 4838982 5094719 5213827 5406420 5662157 5781265 5973858 6229595 6348703 6541296 6797033 6916141 7108734 7364471 7483579 7676172 7931909 8051017 8243610 8499347 8618455 8811048 9066785 ...

output:

488672186

result:

ok 1 number(s): "488672186"

Test #7:

score: 20
Accepted
time: 3ms
memory: 67220kb

input:

1000 144937
189260 200510 334197 345447 388260 457616 479134 490384 504698 533197 561098 573991 602553 624071 628013 628499 635321 649635 678134 706035 718928 747490 769008 772950 773436 780258 794572 823071 850972 863865 864659 892427 913945 917887 918373 922788 925195 939509 968008 995909 1008802 ...

output:

979151496

result:

ok 1 number(s): "979151496"

Test #8:

score: 20
Accepted
time: 10ms
memory: 69312kb

input:

1000 955267
79983 995514 1035250 1719775 1855674 1913421 1950781 1957960 1966589 1968351 1990517 2101118 2202581 2442504 2595814 2675042 2703029 2727524 2810941 2868688 2906048 2913227 2921856 2923618 2945784 2996383 3043340 3056385 3157848 3177959 3397771 3551081 3554246 3630309 3658296 3682791 376...

output:

692731442

result:

ok 1 number(s): "692731442"

Subtask #4:

score: 30
Accepted

Test #9:

score: 30
Accepted
time: 47ms
memory: 210080kb

input:

5000 909960
263288 1173248 1534296 2083208 2309676 2385789 2444256 2993168 3219636 3295749 3354216 3903128 4129596 4205709 4264176 4813088 5039556 5115669 5174136 5723048 5949516 6025629 6084096 6633008 6859476 6935589 6994056 7542968 7769436 7845549 7904016 8205603 8452928 8679396 8755509 8813976 9...

output:

731681576

result:

ok 1 number(s): "731681576"

Test #10:

score: 30
Accepted
time: 37ms
memory: 210104kb

input:

5000 633078
314538 474845 518803 573627 907164 947616 1028632 1107923 1151881 1199740 1206705 1437881 1492463 1540242 1580694 1593600 1622784 1628346 1661324 1661710 1741001 1782655 1784959 1788594 1832818 1839783 1852212 2000185 2070959 2125541 2173320 2179195 2198152 2209332 2213772 2226678 225586...

output:

922398112

result:

ok 1 number(s): "922398112"

Extra Test:

score: 0
Extra Test Passed