QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65841 | #4843. Infectious Disease | yezzz | RE | 5ms | 6648kb | C++17 | 2.0kb | 2022-12-03 19:33:58 | 2022-12-03 19:33:59 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define pii pair<int,int>
using namespace std;
const int mo=1e9+7, N=2e5+5;
int dp[17][40005];
int ksm(int a,int b=mo-2)
{
int res=1;
while(b)
{
if(b&1) res=res*a%mo;
a=a*a%mo; b>>=1;
}
return res;
}
int fac[N], inv[N];
void init()
{
fac[0]=inv[0]=1;
int m=1e5;
for(int i=1;i<=m;i++) fac[i]=fac[i-1]*i%mo;
inv[m]=ksm(fac[m]);
for(int i=m-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%mo;
}
int C(int n,int m)
{
if(m>n || m<0 || n<0) return 0;
return fac[n]*inv[m]%mo*inv[n-m]%mo;
}
void solve(){
init();
int n; cin>>n;
int cnt=0, t=1;
while(t<n) t*=3, cnt++;
dp[0][1]=1;
// dp[1][2]=
for(int i=1;i<cnt;i++)
{
for(int j=0;j<=ksm(2,i);j++)
{
for(int k=1;k<=ksm(2,i-1);k++)
{
// cout<<i<<' '<<j<<' '<<k<<" ???\n";
int sum=n-ksm(3,i-1), c=2*ksm(3,i-1);
dp[i][j]+=dp[i-1][k]*C(2*k,j)%mo*C(sum-2*k,c-(2*k-j))%mo*ksm(C(sum,c))%mo;
if(i==2 && j==0)
{
// cout<<k<<"???\n";
}
dp[i][j]%=mo;
}
// cout<<i<<' '<<j<<' '<<dp[i][j]<<"\n";
}
}
int ans=0;
// cout<<dp[2][0]<<"\n";
// for(int i=1;i<=1000;i++) if(i*ksm(36)%mo==dp[2][0]) cout<<i<<"\n";
// cout<<dp[2][0]<<' '<<35*ksm(36)%mo<<"\n";
for(int i=1;i<cnt;i++) (ans+=i*dp[i][0]%mo)%=mo;
// cout<<ans<<"\n";
// cout<<39*ksm(36)%mo<<"\n";
for(int i=1;i<=ksm(2,cnt+1);i++) (ans+=cnt*dp[cnt-1][i]%mo)%=mo;
cout<<ans<<'\n';
// for(int i=1;i<=500;i++) if(i*ksm(36)%mo==ans) cout<<i<<"\n";
// cout<<ans<<"\n";
// cout<<87*ksm(36)%mo<<"\n";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 6648kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 5ms
memory: 6456kb
input:
114
output:
505208013
result:
ok 1 number(s): "505208013"
Test #3:
score: -100
Runtime Error
input:
14000000