QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#837681#5097. 小 P 爱学习eastcloud10 89ms9840kbC++232.8kb2024-12-30 11:43:072024-12-30 11:43:07

Judging History

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

  • [2024-12-30 11:43:07]
  • 评测
  • 测评结果:10
  • 用时:89ms
  • 内存:9840kb
  • [2024-12-30 11:43:07]
  • 提交

answer


#include<bits/stdc++.h>

#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define IL inline
#define eb emplace_back
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define Fol(i,k,j) for(int i=(k);i>=(j);i--)

#define mod 1000000007
#define N 1502
#define B 501
#define M 101

using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
void write(int x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}

void debug(auto &&...x){
    ((cerr<<x<<' '),...);
    cerr<<'\n';
}

IL int pls(int x,int y){return (x+y>=mod?x+y-mod:x+y);}
IL int sub(int x,int y){return (x-y<0?x-y+mod:x-y);}
IL void Add(int &x,int y){x=pls(x,y);}
IL void Dec(int &x,int y){x=sub(x,y);}
IL int mul(int x,int y){return x*1ll*y%mod;}
IL int qp(int x,int y=mod-2){int ans=1;while(y){if(y&1)ans=mul(ans,x);x=mul(x,x);y>>=1;}return ans;}

int fac[N*M],ifac[N*M],inv[N*M];
IL int C(int x,int y){return mul(fac[x],mul(ifac[y],ifac[x-y]));}
IL void init(){
    fac[0]=ifac[0]=inv[0]=inv[1]=1;
    for(int i=1;i<N;i++)fac[i]=mul(fac[i-1],i);
    ifac[N-1]=qp(fac[N-1]);
    for(int i=N-2;i>=1;i--)ifac[i]=mul(ifac[i+1],i+1);
    for(int i=2;i<N;i++)inv[i]=mul((mod-mod/i),inv[mod%i]);
}

int f[N*M],g[N][N],h[N][N],coef[N],a[N];

int main(){
    #ifdef EAST_CLOUD
    freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    #endif

    int n=read(),m=read();init();n*=m;
    For(i,1,n)a[i]=read();
    f[0]=1;
    For(i,1,n)Fol(j,n/m,1)Add(f[j],mul(f[j-1],a[i]));
    g[0][0]=1;
    For(i,0,n/m){
        For(j,0,n/m){
            if(!g[i][j])continue;
            For(k,1,n/m){
                if(k*m-1>=min(B,n))break;
                if((k+j)*m-(i+1)>n)break;
                Add(g[i+1][j+k],mul(g[i][j],C((j+k)*m-(i+1),j*m-i)));
            }
        }
    }

    h[0][0]=1;
    For(i,0,n/B){
        For(j,0,n/m){
            if(!h[i][j])continue;
            For(k,B/m,n/m){
                if(k*m-1<B)continue;
                if((k+j)*m-(i+1)>n)break;
                Add(h[i+1][j+k],mul(h[i][j],C((j+k)*m-(i+1),j*m-i)));
            }
        }
    }
    For(i,0,n/m){//总共多少组
        For(j,0,min(n/B,i))For(k,0,n/m){
            if(!h[j][k])continue;
            int coef1=h[j][k],coef2=g[i-j][n/m-k];
            Add(coef[i],mul(mul(coef2,coef1),mul(C(n-i,k*m-j),C(i,j))));
        }
    }
    int res=0;
    For(i,1,n/m)Add(res,mul(f[i],coef[i]));
    write(res);
    return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 7648kb

input:

3 4
993987920 851664708 532496582 332334976 645105194 437392477 101400616 97233810 821968468 15736516 160047245 366079295

output:

856280467

result:

ok answer is 856280467

Test #2:

score: 10
Accepted
time: 0ms
memory: 9652kb

input:

2 2
410797770 6809338 472422778 989528224

output:

428410815

result:

ok answer is 428410815

Test #3:

score: 10
Accepted
time: 1ms
memory: 9840kb

input:

1 2
61861880 797258571

output:

859120451

result:

ok answer is 859120451

Test #4:

score: 10
Accepted
time: 1ms
memory: 7732kb

input:

4 4
345828253 333235310 877508155 268177944 892729462 591630803 103568022 189412379 473190308 606582845 39234531 676920516 526713342 584876596 477385922 911117054

output:

130539277

result:

ok answer is 130539277

Test #5:

score: 10
Accepted
time: 1ms
memory: 7612kb

input:

3 4
497837179 320032498 88408654 686869221 955729904 891421702 840622668 700545094 994455042 397227737 872911626 764923114

output:

444700147

result:

ok answer is 444700147

Subtask #2:

score: 0
Time Limit Exceeded

Test #6:

score: 0
Time Limit Exceeded

input:

1500 1
613884366 318223729 617843443 151365784 314748737 778479063 762692152 762329264 560579744 428619194 148701427 891734077 339222910 692588908 180829596 615884679 688697194 981930569 856072945 973079346 407508504 185723413 482150672 944412007 548582506 572572951 297202679 276708377 552007154 951...

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 2ms
memory: 7640kb

input:

100 42
544703372 456304555 178333752 808160596 628160657 264931494 810502429 20342061 203372934 920107110 466566652 470361058 680819469 879463750 668822108 781685938 40434324 800845096 913025163 971899062 986502509 122277391 523016525 579121406 413351231 882719635 632511496 453222515 350376424 37340...

output:

805638967

result:

wrong answer expected 294362854, found 805638967

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 89ms
memory: 7864kb

input:

499 60
136856769 47869549 264538291 600887500 271130365 503375271 979728502 928286478 295751844 413206031 143796624 712745939 41348750 488666164 725432432 529794914 703056452 573552365 225245406 620490759 715276073 987544150 759181034 939466746 354701446 228245827 301255190 24876250 452483821 837389...

output:

837056807

result:

wrong answer expected 157452172, found 837056807

Subtask #5:

score: 0
Time Limit Exceeded

Test #21:

score: 0
Time Limit Exceeded

input:

1500 93
299567650 399978478 101776752 583392666 56762099 127237968 595272440 581887945 332400603 269986805 17840600 323055242 263161884 607605816 966029729 591250421 964262680 642691696 658567473 339363823 715151825 270553684 202478735 193930303 14517687 248178770 917823665 315265457 473654173 33965...

output:


result: