Submission #1354474

#TimeUsernameProblemLanguageResultExecution timeMemory
1354474kokokaiTents (JOI18_tents)C++20
100 / 100
61 ms71020 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define task "text"
#define int long long
const int MOD = 1e9+7;
const int N = 3002;
int fact[N],ifact[N];
int mul(int x,int y){
    return 1LL*x*y%MOD;
}
int add(int x,int y){
    x+=y;
    if(x >= MOD) x-=MOD;
    return x;
}
int pw(int x,int y){
    int res=1;
    while(y){
        if(y&1) res = mul(res,x);
        y>>=1;
        x=mul(x,x);
    }
    return res;
}
void init(){
    fact[0] = 1;
    for(int i=1;i<N;i++) fact[i] = mul(fact[i-1],i);
    ifact[N-1] = pw(fact[N-1],MOD-2);
    for(int i=N-2;i>=0;i--) ifact[i] = mul(ifact[i+1],i+1)%MOD;
}
int C(int n,int k){
    int res = 1LL*fact[n]*ifact[n-k]%MOD *ifact[k]%MOD;
    return res;
}
int E(int n,int m){
    return C(m+n-1,n-1);
}
int dp[N][N];

signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
    }
    init();
    for(int i=0;i<N;i++) dp[0][i]=1;
    int h,w;
    cin>>h>>w;
    for(int i=1;i<N;i++){
        for(int j=0;j<N;j++){
            dp[i][j]=add(dp[i][j],dp[i-1][j]);
            if(j>=2){
                dp[i][j]=add(dp[i][j],mul(dp[i-1][j-2],j*(j-1)/2));
            }
            if(j)dp[i][j]=add(dp[i][j],mul(dp[i-1][j-1],4*j));
        }
    }
    int ans=0;
    //cerr<<dp[1][0]<<'\n';
    for(int r=0;r<=h;r++){
        int nh=h-r;
        int nw=w-2*r;
        if(nh >= 0 && nw >= 0){
            //cerr<<r<<' '<<nw<<' '<<nh<<'\n';
            int res=mul(C(h,r),mul(C(w,2*r),mul(fact[2*r],(pw(pw(2,r),MOD-2)))));
            //cerr<<C(w,2*r)<<' '<<nh<<'\n';
            ans=add(ans,mul(res,dp[nw][nh]));
        }
    }
    cout<<ans-1<<'\n';
}



Compilation message (stderr)

tents.cpp: In function 'int main()':
tents.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...