Submission #134419

# Submission time Handle Problem Language Result Execution time Memory
134419 2019-07-22T16:32:01 Z duality Tents (JOI18_tents) C++11
100 / 100
240 ms 71032 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define MOD 1000000007

LLI inv(LLI n) {
    int e = MOD-2;
    LLI r = 1;
    while (e > 0) {
        if (e & 1) r *= n,r %= MOD;
        e >>= 1;
        n *= n,n %= MOD;
    }
    return r;
}
LLI fact[3001],invf[3001],invpow2[6001];
LLI dp[3001][3001];
LLI choose(LLI n,LLI k) {
    return (fact[n]*((invf[k]*invf[n-k]) % MOD)) % MOD;
}
int main() {
    int H,W;
    cin >> H >> W;

    int i,j;
    LLI ans = 0;
    fact[0] = invf[0] = 1;
    for (i = 1; i <= max(H,W); i++) fact[i] = (fact[i-1]*i) % MOD,invf[i] = inv(fact[i]);
    invpow2[0] = 1;
    for (i = 1; i <= H+W; i++) invpow2[i] = (invpow2[i-1]*inv(2)) % MOD;
    for (i = 0; i <= W; i++) dp[0][i] = 1;
    for (i = 1; i <= H; i++) {
        dp[i][0] = 1;
        for (j = 1; j <= W; j++) dp[i][j] = (dp[i-1][j]+4*j*dp[i-1][j-1]) % MOD;
    }
    for (i = 0; i <= H; i++) {
        for (j = 0; j <= W; j++) {
            if ((i+2*j <= H) && (j+2*i <= W)) {
                LLI x = (((choose(H,i)*choose(W,2*i)) % MOD)*fact[2*i]) % MOD;
                LLI y = (((choose(W-2*i,j)*choose(H-i,2*j)) % MOD)*fact[2*j]) % MOD;
                ans += ((x*y) % MOD)*((dp[H-i-2*j][W-j-2*i]*invpow2[i+j]) % MOD);
                ans %= MOD;
            }
        }
    }
    cout << (ans+MOD-1) % MOD << endl;

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 3 ms 1400 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 3 ms 1528 KB Output is correct
9 Correct 2 ms 888 KB Output is correct
10 Correct 4 ms 1784 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 4 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 3 ms 1400 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 3 ms 1528 KB Output is correct
9 Correct 2 ms 888 KB Output is correct
10 Correct 4 ms 1784 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 4 ms 2296 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 10 ms 9720 KB Output is correct
15 Correct 144 ms 55288 KB Output is correct
16 Correct 7 ms 4088 KB Output is correct
17 Correct 24 ms 12924 KB Output is correct
18 Correct 39 ms 17144 KB Output is correct
19 Correct 165 ms 63156 KB Output is correct
20 Correct 132 ms 50996 KB Output is correct
21 Correct 83 ms 34040 KB Output is correct
22 Correct 87 ms 35576 KB Output is correct
23 Correct 35 ms 27128 KB Output is correct
24 Correct 240 ms 71032 KB Output is correct
25 Correct 181 ms 61440 KB Output is correct
26 Correct 204 ms 66680 KB Output is correct
27 Correct 216 ms 68984 KB Output is correct