답안 #110095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110095 2019-05-09T12:40:07 Z Saboon Tents (JOI18_tents) C++14
48 / 100
2000 ms 34440 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 3000 + 10;
const int mod = 1e9 + 7;
int dp[maxn][maxn];

int power(int a, int b){
	if (b == 0)
		return 1;
	int ret = power(a, b / 2);
	ret = 1ll * ret * ret % mod;
	if (b & 1)
		return 1ll * ret * a % mod;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i <= max(n, m); i++)
		dp[i][0] = dp[0][i] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if (i == 1){
				dp[i][j] = 4 * j + 1ll * j * (j - 1) % mod * power(2, mod - 2) % mod + 1;
				dp[i][j] %= mod;
				continue;
			}
			if (j == 1){
				dp[i][j] = 4 * i + 1ll * i * (i - 1) % mod * power(2, mod - 2) % mod + 1;
				dp[i][j] %= mod;
				continue;
			}
			dp[i][j] = dp[i - 1][j];
			dp[i][j] = (dp[i][j] + 4ll * dp[i - 1][j - 1] * j) % mod;
			dp[i][j] = (dp[i][j] + 1ll * dp[i - 1][j - 2] * j % mod * (j - 1) % mod * power(2, mod - 2) % mod) % mod;
			dp[i][j] = (dp[i][j] + 1ll * dp[i - 2][j - 1] * j % mod * (i - 1) % mod) % mod;
		}
	}
	cout << (dp[n][m] - 1 + mod) % mod << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 8 ms 1408 KB Output is correct
6 Correct 9 ms 1408 KB Output is correct
7 Correct 9 ms 1152 KB Output is correct
8 Correct 8 ms 1408 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 16 ms 1664 KB Output is correct
11 Correct 4 ms 1508 KB Output is correct
12 Correct 32 ms 2056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 8 ms 1408 KB Output is correct
6 Correct 9 ms 1408 KB Output is correct
7 Correct 9 ms 1152 KB Output is correct
8 Correct 8 ms 1408 KB Output is correct
9 Correct 3 ms 896 KB Output is correct
10 Correct 16 ms 1664 KB Output is correct
11 Correct 4 ms 1508 KB Output is correct
12 Correct 32 ms 2056 KB Output is correct
13 Correct 10 ms 7808 KB Output is correct
14 Correct 11 ms 9600 KB Output is correct
15 Correct 1762 ms 32864 KB Output is correct
16 Correct 121 ms 8108 KB Output is correct
17 Correct 388 ms 12536 KB Output is correct
18 Correct 481 ms 11796 KB Output is correct
19 Execution timed out 2029 ms 34440 KB Time limit exceeded
20 Halted 0 ms 0 KB -