QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65842#4843. Infectious DiseaseyezzzRE 6ms6240kbC++172.0kb2022-12-03 19:34:572022-12-03 19:34:58

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-03 19:34:58]
  • 评测
  • 测评结果:RE
  • 用时:6ms
  • 内存:6240kb
  • [2022-12-03 19:34:57]
  • 提交

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][400005];
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: 4ms
memory: 6240kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 6ms
memory: 6228kb

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: -100
Runtime Error

input:

14000000

output:


result: