답안 #353683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
353683 2021-01-21T09:26:53 Z shivensinha4 Tents (JOI18_tents) C++17
100 / 100
272 ms 70764 KB
#include "bits/stdc++.h"
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'

const ll mod = 1e9+7;

ll ncr(ll n, ll r) {
	if (r == 0) return 1;
	if (r == 1) return n;
	if (r == 2) return ((n*(n-1))/2 % mod);
	assert(false);
}

int main() {
#ifdef mlocal
	freopen("test.in", "r", stdin);
#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m; cin >> n >> m;
	ll dp[n+1][m+1]; // [row][empty][light]
	memset(dp, 0, sizeof(dp));
	
	for_(i, 0, m+1) dp[n][i] = 1;
	for (int i = n-1;  i >= 0; i--) {
		for_(emp, 0, m+1) {
			dp[i][emp] = dp[i+1][emp];
			if (emp >= 2) {
				dp[i][emp] += ((dp[i+1][emp-2] * ncr(emp, 2)) % mod);
				if (dp[i][emp] >= mod) dp[i][emp] -= mod;
			}
			
			if (emp >= 1) {
				if (i < n-1) dp[i][emp] += (emp * (n-i-1) * dp[i+2][emp-1]) % mod;
				if (dp[i][emp] >= mod) dp[i][emp] -= mod;
				dp[i][emp] += (((dp[i+1][emp-1] * 4) % mod) * emp) % mod;
				if (dp[i][emp] >= mod) dp[i][emp] -= mod;
			}
		}
	}
	
	cout << (dp[0][m]-1+mod) % mod << endl;
	
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 4 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 4 ms 1004 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 172 ms 44184 KB Output is correct
16 Correct 10 ms 3180 KB Output is correct
17 Correct 38 ms 10092 KB Output is correct
18 Correct 45 ms 12396 KB Output is correct
19 Correct 178 ms 51308 KB Output is correct
20 Correct 146 ms 41068 KB Output is correct
21 Correct 105 ms 27244 KB Output is correct
22 Correct 111 ms 26860 KB Output is correct
23 Correct 60 ms 14956 KB Output is correct
24 Correct 272 ms 70764 KB Output is correct
25 Correct 184 ms 52588 KB Output is correct
26 Correct 231 ms 60268 KB Output is correct
27 Correct 261 ms 68076 KB Output is correct