QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454051 | #8521. Pattern Search II | ucup-team1525# | WA | 0ms | 3872kb | C++20 | 1.3kb | 2024-06-24 16:09:20 | 2024-06-24 16:09:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3;
const int mod=1e9+7;
int add(int x,int y){ return (x+=y)>=mod?x-mod:x; }
int sub(int x,int y){ return (x-=y)<0?x+mod:x; }
int ksm(ll x,int tp,int s=1){
for(;tp;x=x*x%mod,tp>>=1) if(tp&1) s=x*s%mod;
return s;
}
int C[N+5][N+5];
int ikp[N+5];
int n;
int a[N+5];
int f[55][N+5];
int g[N*2+5];
int ans;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
ikp[0]=1;
for(int i=1;i<=n;i++)
ikp[i]=ksm(2,mod-2,ikp[i-1]);
C[0][0]=1;
for(int i=1;i<=n;i++){
C[i][0]=C[i][i]=1;
for(int j=1;j<i;j++)
C[i][j]=add(C[i-1][j],C[i-1][j-1]);
}
for(int i=0;i<n;i++)
f[0][i]=1ll*C[n-1][i]*ikp[n-1]%mod;
for(int i=0;i<=50;i++){
int m=0;
for(int j=1;j<=n;j++){
if(a[j]==i)
ans=add(ans,f[i][0]);
if(a[j]>i)
m++;
}
ans=1ll*ans*ikp[m]%mod;
memset(g,0,sizeof g);
for(int j=0;j<=n;j++)
for(int k=0;k<=m;k++)
g[j+k]=(g[j+k]+1ll*f[i][j]*C[m][k])%mod;
for(int j=0;j<n*2;j++)
f[i+1][j/2]=(f[i+1][j/2]+1ll*g[j]*ikp[m])%mod;
printf("%d\n",ans);
}
printf("%d\n",sub(1,ans));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3872kb
input:
aabbaab
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
result:
wrong answer 1st numbers differ - expected: '8', found: '0'