답안 #1033969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033969 2024-07-25T08:09:57 Z fimh Tents (JOI18_tents) C++14
100 / 100
265 ms 59344 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define pll pair<long long, long long>
#define se second
#define isz(a) (int)a.size()
using namespace std;

const long long inf = 1e18;
const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;

int n, m, divi;
int cc[maxn][maxn];

long long binpow(int x, int y){
    long long ans = 1;
    while (y){
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod; y >>= 1;
    }
    return ans;
}

int dp(int i, int j){
    if (i < 0 || j < 0) return 0;
    if (cc[i][j]) return cc[i][j];
    int &ans = cc[i][j];
    ans += dp(i - 1, j); ans %= mod;
    ans += dp(i - 1, j - 1) * 4 % mod * j % mod; ans %= mod;
    ans += dp(i - 1, j - 2) * j % mod * (j - 1) % mod * divi % mod; ans %= mod;
    ans += dp(i - 2, j - 1) * j % mod * (i - 1) % mod; ans %= mod;
    return ans;
}   

void solve(){
    cin >> n >> m;
    divi = binpow(2, mod - 2);
    for (int i = 0; i <= n; ++i) cc[i][0] = 1;
    for (int i = 0; i <= m; ++i) cc[0][i] = 1;
    int ans = (dp(n, m) - 1 + mod) % mod;
    cout << ans << "\n";
}   

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t = 1; // cin >> t;
    while (t--){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 4584 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 4 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 4584 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 4 ms 8540 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 4 ms 25180 KB Output is correct
15 Correct 159 ms 55892 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 17 ms 17036 KB Output is correct
18 Correct 37 ms 25040 KB Output is correct
19 Correct 183 ms 59344 KB Output is correct
20 Correct 146 ms 48464 KB Output is correct
21 Correct 81 ms 34124 KB Output is correct
22 Correct 104 ms 38532 KB Output is correct
23 Correct 70 ms 40032 KB Output is correct
24 Correct 265 ms 59108 KB Output is correct
25 Correct 185 ms 53144 KB Output is correct
26 Correct 203 ms 57428 KB Output is correct
27 Correct 224 ms 57684 KB Output is correct