Submission #1088583

# Submission time Handle Problem Language Result Execution time Memory
1088583 2024-09-14T15:51:21 Z DobromirAngelov Tents (JOI18_tents) C++14
100 / 100
88 ms 70996 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int MOD=1e9+7;
const int MAXN=3005;

int h,w;
long long dp[MAXN][MAXN];
long long fact[MAXN];
long long invF[MAXN];

int fastPow(long long x,int pwr)
{
    long long ret=1;
    while(pwr>0)
    {
        if(pwr&1) ret=ret*x%MOD;
        pwr/=2;
        x=x*x%MOD;
    }
    return ret;
}

int inverse(int x)
{
    return fastPow(x,MOD-2);
}

void precomp()
{
    for(int i=0;i<=w;i++) dp[0][i]=1;
    for(int i=0;i<=h;i++) dp[i][0]=1;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            dp[i][j]=(dp[i][j-1]+i*dp[i-1][j-1]*4)%MOD;
        }
    }

    fact[0]=1;
    for(int i=1;i<MAXN;i++) fact[i]=fact[i-1]*i%MOD;
    for(int i=0;i<MAXN;i++) invF[i]=inverse(fact[i]);
}

int comb(int n,int k)
{
    return (fact[n]*invF[n-k]%MOD)*invF[k]%MOD;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>h>>w;

    precomp();

    long long ans=0;
    long long P1=1;
    for(int r=0;r<=min(h,w/2);r++)
    {
        long long cur1=comb(h,r);
        if(r>0) P1=P1*comb(w-2*r+2,2)%MOD;
        cur1=cur1*P1%MOD;
        long long P2=1;
        for(int c=0;c<=min((h-r)/2,w-2*r);c++)
        {
            long long cur2=cur1*comb(w-2*r,c)%MOD;
            if(c>0) P2=P2*comb(h-r-2*c+2,2)%MOD;
            cur2=cur2*P2%MOD;

            cur2=cur2*dp[h-r-2*c][w-2*r-c]%MOD;
            ans+=cur2;
            if(ans>=MOD) ans-=MOD;
        }
    }

    cout<<(ans-1+MOD)%MOD<<endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 1928 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 1928 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 56 ms 55180 KB Output is correct
16 Correct 4 ms 4184 KB Output is correct
17 Correct 12 ms 12892 KB Output is correct
18 Correct 16 ms 17088 KB Output is correct
19 Correct 66 ms 63160 KB Output is correct
20 Correct 51 ms 50920 KB Output is correct
21 Correct 37 ms 33880 KB Output is correct
22 Correct 37 ms 35412 KB Output is correct
23 Correct 19 ms 27224 KB Output is correct
24 Correct 88 ms 70996 KB Output is correct
25 Correct 75 ms 61248 KB Output is correct
26 Correct 75 ms 66784 KB Output is correct
27 Correct 83 ms 69200 KB Output is correct