Submission #362325

# Submission time Handle Problem Language Result Execution time Memory
362325 2021-02-02T16:09:23 Z knightron0 Tents (JOI18_tents) C++14
100 / 100
448 ms 71404 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double

const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 3005;

int n, m;
int dp[MAXN][MAXN];
int modinv = 0;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

int nc2(int n){
	int ans = n%MOD;
	ans *= (n-1+MOD)%MOD;
	ans %= MOD;
	return ans*modinv;
}

int f(int lx, int ly){
	if(lx < 0 || ly < 0) return 0;
	if(lx == 0 || ly == 0) return 1;
	if(dp[lx][ly] != -1) return dp[lx][ly];
	return dp[lx][ly]= (((4*((lx%MOD)*(f(lx-1, ly-1)%MOD))%MOD)%MOD) + ((((ly-1)%MOD)*(lx%MOD)*(f(lx-1, ly-2)%MOD)%MOD)%MOD) + ((nc2(lx)%MOD)*(f(lx-2,ly-1)%MOD)%MOD) + ((f(lx, ly-1)%MOD)%MOD))%MOD;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif
    cin>>n>>m;
    clr(dp, -1);
    modinv = fastexpo(2, MOD-2);
    cout<<(f(n, m)+MOD-1)%MOD<<endl;
    return 0;
}



# Verdict Execution time Memory Grader output
1 Correct 41 ms 71020 KB Output is correct
2 Correct 39 ms 71020 KB Output is correct
3 Correct 39 ms 71020 KB Output is correct
4 Correct 39 ms 71020 KB Output is correct
5 Correct 41 ms 71020 KB Output is correct
6 Correct 40 ms 71020 KB Output is correct
7 Correct 40 ms 71020 KB Output is correct
8 Correct 39 ms 71020 KB Output is correct
9 Correct 39 ms 71020 KB Output is correct
10 Correct 40 ms 71020 KB Output is correct
11 Correct 39 ms 71020 KB Output is correct
12 Correct 42 ms 71020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 71020 KB Output is correct
2 Correct 39 ms 71020 KB Output is correct
3 Correct 39 ms 71020 KB Output is correct
4 Correct 39 ms 71020 KB Output is correct
5 Correct 41 ms 71020 KB Output is correct
6 Correct 40 ms 71020 KB Output is correct
7 Correct 40 ms 71020 KB Output is correct
8 Correct 39 ms 71020 KB Output is correct
9 Correct 39 ms 71020 KB Output is correct
10 Correct 40 ms 71020 KB Output is correct
11 Correct 39 ms 71020 KB Output is correct
12 Correct 42 ms 71020 KB Output is correct
13 Correct 39 ms 71148 KB Output is correct
14 Correct 40 ms 71020 KB Output is correct
15 Correct 274 ms 71404 KB Output is correct
16 Correct 57 ms 71148 KB Output is correct
17 Correct 94 ms 71148 KB Output is correct
18 Correct 100 ms 71148 KB Output is correct
19 Correct 322 ms 71404 KB Output is correct
20 Correct 271 ms 71296 KB Output is correct
21 Correct 184 ms 71276 KB Output is correct
22 Correct 175 ms 71276 KB Output is correct
23 Correct 61 ms 71020 KB Output is correct
24 Correct 448 ms 71404 KB Output is correct
25 Correct 338 ms 71276 KB Output is correct
26 Correct 380 ms 71276 KB Output is correct
27 Correct 439 ms 71404 KB Output is correct