Submission #363887

# Submission time Handle Problem Language Result Execution time Memory
363887 2021-02-07T12:51:51 Z Kevin_Zhang_TW Asceticism (JOI18_asceticism) C++17
49 / 100
7 ms 8300 KB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 3010, p = 1e9 + 7;

ll dp[MAX_N][MAX_N];

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

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, k;
	cin >> n >> k;
	if (n >= MAX_N) return 1;

	dp[1][0] = 1;

	for (int i = 2;i <= n;++i) {
		for (int j = 0;j < i;++j)
			dp[i][j] = (dp[i-1][j] * (j + 1) + 
				(j ? dp[i-1][j-1] : 0) * (i - j)) % p;

//		for (int j = 0;j < i;++j) {
//			dp[i + 1][j] += dp[i][j] * (j + 1);
//			dp[i + 1][j + 1] += dp[i][j] * (i - j);
//		}
//
//			add(dp[i + 1][j], dp[i][j] * (j + 1) % p);
//			add(dp[i + 1][j + 1], dp[i][j] * (i + 1 - (j + 1)) % p);
	}

	cout << dp[n][k-1] << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 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 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 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 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 1900 KB Output is correct
13 Correct 1 ms 1900 KB Output is correct
14 Correct 1 ms 1900 KB Output is correct
15 Correct 2 ms 1900 KB Output is correct
16 Correct 1 ms 1900 KB Output is correct
17 Correct 1 ms 1260 KB Output is correct
18 Correct 1 ms 1644 KB Output is correct
19 Correct 1 ms 1004 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 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 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 1900 KB Output is correct
13 Correct 1 ms 1900 KB Output is correct
14 Correct 1 ms 1900 KB Output is correct
15 Correct 2 ms 1900 KB Output is correct
16 Correct 1 ms 1900 KB Output is correct
17 Correct 1 ms 1260 KB Output is correct
18 Correct 1 ms 1644 KB Output is correct
19 Correct 1 ms 1004 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 6 ms 8300 KB Output is correct
22 Correct 6 ms 8300 KB Output is correct
23 Correct 6 ms 8300 KB Output is correct
24 Correct 7 ms 8300 KB Output is correct
25 Correct 6 ms 8300 KB Output is correct
26 Correct 6 ms 8300 KB Output is correct
27 Correct 6 ms 8300 KB Output is correct
28 Correct 3 ms 4204 KB Output is correct
29 Correct 1 ms 1260 KB Output is correct
30 Correct 6 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 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 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 1900 KB Output is correct
13 Correct 1 ms 1900 KB Output is correct
14 Correct 1 ms 1900 KB Output is correct
15 Correct 2 ms 1900 KB Output is correct
16 Correct 1 ms 1900 KB Output is correct
17 Correct 1 ms 1260 KB Output is correct
18 Correct 1 ms 1644 KB Output is correct
19 Correct 1 ms 1004 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 6 ms 8300 KB Output is correct
22 Correct 6 ms 8300 KB Output is correct
23 Correct 6 ms 8300 KB Output is correct
24 Correct 7 ms 8300 KB Output is correct
25 Correct 6 ms 8300 KB Output is correct
26 Correct 6 ms 8300 KB Output is correct
27 Correct 6 ms 8300 KB Output is correct
28 Correct 3 ms 4204 KB Output is correct
29 Correct 1 ms 1260 KB Output is correct
30 Correct 6 ms 8192 KB Output is correct
31 Runtime error 1 ms 364 KB Execution failed because the return code was nonzero
32 Halted 0 ms 0 KB -