답안 #769462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
769462 2023-06-29T15:33:30 Z LucaIlie Tents (JOI18_tents) C++17
100 / 100
989 ms 199764 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5000;
const int MOD = 1e9 + 7;

long long dp[MAX_N][MAX_N], fact[MAX_N], comb[MAX_N][MAX_N];

int lgPut( int x, int n ) {
    if ( n == 0 )
        return 1;

    int ans = lgPut( x, n / 2 );
    ans = (long long)ans * ans % MOD;
    if ( n % 2 == 1 )
        ans = (long long)ans * x % MOD;

    return ans;
}

int invers( int x ) {
    return lgPut( x, MOD - 2 );
}

int main() {
    int n, m;

    cin >> n >> m;

    for ( int i = 0; i <= n; i++ )
        dp[i][0] = 1;
    for ( int i = 0; i <= m; i++ )
        dp[0][i] = 1;
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= m; j++ )
            dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1] * j * 4) % MOD;
    }

    fact[0] = 1;
    for ( int i = 1; i < MAX_N; i++ )
        fact[i] = fact[i - 1] * i % MOD;
    for ( int i = 0; i < MAX_N; i++ ) {
        comb[i][0] = 1;
        for ( int j = 1; j <= i; j++ )
            comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % MOD;
    }

    long long sol = 0;
    for ( int a = 0; a <= n; a++ ) {
        for ( int b = 0; b <= m; b++ ) {
            if ( n - a - 2 * b < 0 || m - 2 * a - b < 0 )
                continue;

            long long chooseA = comb[n][a] * comb[m][a] % MOD * comb[m - a][a] % MOD * fact[a] % MOD * fact[a] % MOD * invers( lgPut( 2, a ) ) % MOD;
            long long chooseB = comb[n - a][b] * comb[n - a - b][b] % MOD * comb[m - 2 * a][b] % MOD * fact[b] % MOD * fact[b] % MOD * invers( lgPut( 2, b ) )% MOD;
            sol = (sol + chooseA * chooseB % MOD * dp[n - a - 2 * b][m - 2 * a - b]) % MOD;
        }
    }
    cout << sol - 1;


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 117196 KB Output is correct
2 Correct 50 ms 117120 KB Output is correct
3 Correct 59 ms 117384 KB Output is correct
4 Correct 59 ms 117996 KB Output is correct
5 Correct 60 ms 117524 KB Output is correct
6 Correct 63 ms 118280 KB Output is correct
7 Correct 58 ms 117756 KB Output is correct
8 Correct 61 ms 118244 KB Output is correct
9 Correct 59 ms 117708 KB Output is correct
10 Correct 60 ms 118656 KB Output is correct
11 Correct 56 ms 117160 KB Output is correct
12 Correct 66 ms 119100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 117196 KB Output is correct
2 Correct 50 ms 117120 KB Output is correct
3 Correct 59 ms 117384 KB Output is correct
4 Correct 59 ms 117996 KB Output is correct
5 Correct 60 ms 117524 KB Output is correct
6 Correct 63 ms 118280 KB Output is correct
7 Correct 58 ms 117756 KB Output is correct
8 Correct 61 ms 118244 KB Output is correct
9 Correct 59 ms 117708 KB Output is correct
10 Correct 60 ms 118656 KB Output is correct
11 Correct 56 ms 117160 KB Output is correct
12 Correct 66 ms 119100 KB Output is correct
13 Correct 54 ms 117136 KB Output is correct
14 Correct 62 ms 126568 KB Output is correct
15 Correct 607 ms 172036 KB Output is correct
16 Correct 66 ms 120820 KB Output is correct
17 Correct 128 ms 129744 KB Output is correct
18 Correct 205 ms 133968 KB Output is correct
19 Correct 707 ms 179824 KB Output is correct
20 Correct 591 ms 167880 KB Output is correct
21 Correct 384 ms 150756 KB Output is correct
22 Correct 385 ms 152448 KB Output is correct
23 Correct 118 ms 143948 KB Output is correct
24 Correct 989 ms 199764 KB Output is correct
25 Correct 757 ms 179740 KB Output is correct
26 Correct 838 ms 188464 KB Output is correct
27 Correct 937 ms 196660 KB Output is correct