답안 #478329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478329 2021-10-07T03:48:03 Z Mike4235 Tents (JOI18_tents) C++17
100 / 100
217 ms 70852 KB
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
// only when really needed

/* GNU G++17 7.3.0: No long long for faster code
   GNU G++17 9.2.0 (64 bit, msys 2): Long long only for faster code */
 
#include <bits/stdc++.h>
  
#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long

#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pb push_back
 
/*
__builtin_popcountll(x) : Number of 1-bit
__builtin_ctzll(x) : Number of trailing 0
*/
 
#define PI 3.1415926535897932384626433832795
#define INF 1000000000000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6

using namespace std;

void add(int& a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int mul(int a, int b) {
    return a * b % MOD;
}

int n, m;
int dp[3005][3005];

signed main() {
    
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // freopen("cf.inp", "r", stdin);
    // freopen("cf.out", "w", stdout);

    cin >> n >> m;

    for1(i,0,n) dp[i][0] = 1;
    for1(j,0,m) dp[0][j] = 1;

    for1(i,1,n) {
        for1(j,1,m) {
            if (i > 1) add(dp[i][j], mul(dp[i - 2][j - 1], j * (i - 1)));
            if (j > 1) add(dp[i][j], mul(dp[i - 1][j - 2], j * (j - 1) / 2));
            add(dp[i][j], dp[i - 1][j]);
            add(dp[i][j], mul(dp[i - 1][j - 1], 4 * j));
        }
    }

    cout << (dp[n][m] - 1 + MOD) % MOD;
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 1356 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 1740 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 3 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 1356 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 1740 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 3 ms 2124 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 5 ms 9676 KB Output is correct
15 Correct 144 ms 55196 KB Output is correct
16 Correct 10 ms 4044 KB Output is correct
17 Correct 31 ms 12760 KB Output is correct
18 Correct 40 ms 16976 KB Output is correct
19 Correct 157 ms 62916 KB Output is correct
20 Correct 128 ms 50848 KB Output is correct
21 Correct 83 ms 33732 KB Output is correct
22 Correct 84 ms 35464 KB Output is correct
23 Correct 50 ms 27044 KB Output is correct
24 Correct 217 ms 70852 KB Output is correct
25 Correct 157 ms 61216 KB Output is correct
26 Correct 187 ms 66576 KB Output is correct
27 Correct 200 ms 69008 KB Output is correct