답안 #55464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55464 2018-07-07T15:25:46 Z szawinis Tents (JOI18_tents) C++17
100 / 100
167 ms 71348 KB
#include <bits/stdc++.h>
using namespace std;
#define fori(i, a, b) for(int i = (int) a; i <= (int) b; ++i)
#define rofi(i, b, a) for(int i = (int) b; i >= (int) a; --i)
#define foreach(tt, a) for(auto &tt: a)
#define all(a) begin(a), end(a)
#define csz(a) (int) a.size()
#define pb push_back
#define epb emplace_back
#define mp make_pair
#define load(a, v) fill(begin(a), end(a), v)
#define load_mem(a, v) memset(a, v, sizeof(a));
#define iostream_optimize() ios::sync_with_stdio(false); cin.tie(0);
using ll = long long;
const ll MOD = 1e9+7, LINF = 1e16+1;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll P1 = 31, P2 = 37, M1 = 1e9+7, M2 = 1e9+9;

// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<< END TEMPLATE >>>>>>>>>>>>>>>>>>>>>>>>>>> */
const int N = 3001;

int n, m, fact[N], inv[N];
ll ans, dp[N][N];

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

ll mul(ll a, ll b) {
	a *= b;
	if(a >= MOD) a %= MOD;
	return a;
}

ll modPow(ll b, ll e) {
	if(e == 0) return 1;
	if(e == 1) return b;
	return mul(modPow(mul(b, b), e >> 1), modPow(b, e & 1));
}

ll C(ll n, ll k) {
	return mul(fact[n], mul(inv[k], inv[n-k]));
}

int main() {
	iostream_optimize();
	fact[0] = inv[0] = 1;
	fori(i, 1, N-1) {
		fact[i] = mul(fact[i-1], i);
		inv[i] = modPow(fact[i], MOD-2);
	}

	cin >> n >> m;

	fori(j, 0, n) dp[0][j] = 1;
	fori(i, 1, m) {
		fori(j, 0, n) {
			add(dp[i][j], dp[i-1][j]);
			if(j > 0) add(dp[i][j], mul(dp[i-1][j-1], j*4));
			if(j > 1) add(dp[i][j], mul(dp[i-1][j-2], j*(j-1)/2));
		}
	}
	fori(k, 0, min(n, m >> 1)) {
		ll combi = mul(C(n, k), C(m, k << 1));
		combi = mul(combi, mul(fact[k << 1], modPow(inv[2], k)));
		add(ans, mul(dp[m-(k << 1)][n-k], combi));
	}
	cout << (ans-1+MOD) % MOD;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 1128 KB Output is correct
3 Correct 4 ms 1128 KB Output is correct
4 Correct 2 ms 1128 KB Output is correct
5 Correct 4 ms 1716 KB Output is correct
6 Correct 4 ms 1716 KB Output is correct
7 Correct 5 ms 1744 KB Output is correct
8 Correct 3 ms 1744 KB Output is correct
9 Correct 3 ms 1744 KB Output is correct
10 Correct 5 ms 1744 KB Output is correct
11 Correct 7 ms 2008 KB Output is correct
12 Correct 7 ms 2696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 1128 KB Output is correct
3 Correct 4 ms 1128 KB Output is correct
4 Correct 2 ms 1128 KB Output is correct
5 Correct 4 ms 1716 KB Output is correct
6 Correct 4 ms 1716 KB Output is correct
7 Correct 5 ms 1744 KB Output is correct
8 Correct 3 ms 1744 KB Output is correct
9 Correct 3 ms 1744 KB Output is correct
10 Correct 5 ms 1744 KB Output is correct
11 Correct 7 ms 2008 KB Output is correct
12 Correct 7 ms 2696 KB Output is correct
13 Correct 12 ms 8204 KB Output is correct
14 Correct 5 ms 8204 KB Output is correct
15 Correct 108 ms 48276 KB Output is correct
16 Correct 15 ms 48276 KB Output is correct
17 Correct 31 ms 48276 KB Output is correct
18 Correct 46 ms 48276 KB Output is correct
19 Correct 121 ms 53412 KB Output is correct
20 Correct 114 ms 53412 KB Output is correct
21 Correct 76 ms 53412 KB Output is correct
22 Correct 70 ms 53412 KB Output is correct
23 Correct 35 ms 53412 KB Output is correct
24 Correct 167 ms 71348 KB Output is correct
25 Correct 119 ms 71348 KB Output is correct
26 Correct 128 ms 71348 KB Output is correct
27 Correct 142 ms 71348 KB Output is correct