답안 #362324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362324 2021-02-02T16:08:12 Z knightron0 Tents (JOI18_tents) C++14
48 / 100
2000 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 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*fastexpo(2, MOD-2);
}

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);
    cout<<(f(n, m)+MOD-1)%MOD<<endl;
    return 0;
}



# 결과 실행 시간 메모리 Grader output
1 Correct 39 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 40 ms 71020 KB Output is correct
5 Correct 47 ms 71020 KB Output is correct
6 Correct 42 ms 71020 KB Output is correct
7 Correct 48 ms 71020 KB Output is correct
8 Correct 40 ms 71020 KB Output is correct
9 Correct 39 ms 71020 KB Output is correct
10 Correct 47 ms 71020 KB Output is correct
11 Correct 40 ms 71020 KB Output is correct
12 Correct 67 ms 71020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 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 40 ms 71020 KB Output is correct
5 Correct 47 ms 71020 KB Output is correct
6 Correct 42 ms 71020 KB Output is correct
7 Correct 48 ms 71020 KB Output is correct
8 Correct 40 ms 71020 KB Output is correct
9 Correct 39 ms 71020 KB Output is correct
10 Correct 47 ms 71020 KB Output is correct
11 Correct 40 ms 71020 KB Output is correct
12 Correct 67 ms 71020 KB Output is correct
13 Correct 40 ms 71276 KB Output is correct
14 Correct 39 ms 71020 KB Output is correct
15 Correct 1611 ms 71276 KB Output is correct
16 Correct 183 ms 71276 KB Output is correct
17 Correct 509 ms 71272 KB Output is correct
18 Correct 538 ms 71220 KB Output is correct
19 Correct 1937 ms 71404 KB Output is correct
20 Correct 1608 ms 71404 KB Output is correct
21 Correct 1182 ms 71404 KB Output is correct
22 Correct 970 ms 71312 KB Output is correct
23 Correct 207 ms 71020 KB Output is correct
24 Execution timed out 2086 ms 71276 KB Time limit exceeded
25 Halted 0 ms 0 KB -