Submission #463628

# Submission time Handle Problem Language Result Execution time Memory
463628 2021-08-11T11:52:59 Z huukhang Kangaroo (CEOI16_kangaroo) C++11
100 / 100
31 ms 31792 KB
/*
						   Khangnh's code

“You can either experience the pain of discipline or the pain of regret. 
						The choice is yours.”
*/

// - Only when necessary :d
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define fileopen(a, b) freopen(((string)a + ".inp").c_str(), "r", stdin); freopen(((string)b + ".out").c_str(), "w", stdout);

#define ll long long
// #define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define eb emplace_back
typedef pair<int, int> pii;

const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const double eps = 1e-9;

inline void sadd(ll &x, const ll &y) {x = (x + y)%mod;}
inline ll mmul(const ll &x, const ll &y) {return (x*y)%mod;}

int n, s, e;
ll dp[2005][2005];

// - Main idea: for a more detailed explanation, read
// +) https://codeforces.com/blog/entry/47764?#comment-704139
void solve() {
	cin >> n >> s >> e;

	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= i; ++j) {
			if (i + 1 == s || i + 1 == e) {
				sadd(dp[i + 1][j + 1], dp[i][j]);
				sadd(dp[i + 1][j], dp[i][j]);
			} else {
				sadd(dp[i + 1][j - 1], mmul(dp[i][j], j - 1));
				sadd(dp[i + 1][j + 1], mmul(dp[i][j], j + 1 - (i + 1 > s) - (i + 1 > e)));
			}
		}
	}

	cout << dp[n][1];
}

signed main() {
	#ifdef LOCAL
		fileopen("input", "output");
		auto start = clock();
	#endif
	#ifndef LOCAL
//		fileopen("LAH", "LAH");
	#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int test = 1;
//	cin >> test;
	for (int tc = 1; tc <= test; ++tc) solve();
	#ifdef LOCAL
		auto end = clock();
		cout << "\n\nExecution time : " << double(end - start)/CLOCKS_PER_SEC << "[s]";
	#endif
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31692 KB Output is correct
2 Correct 13 ms 31684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31692 KB Output is correct
2 Correct 13 ms 31684 KB Output is correct
3 Correct 13 ms 31672 KB Output is correct
4 Correct 14 ms 31760 KB Output is correct
5 Correct 15 ms 31672 KB Output is correct
6 Correct 14 ms 31764 KB Output is correct
7 Correct 14 ms 31724 KB Output is correct
8 Correct 15 ms 31692 KB Output is correct
9 Correct 15 ms 31664 KB Output is correct
10 Correct 14 ms 31732 KB Output is correct
11 Correct 14 ms 31792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31692 KB Output is correct
2 Correct 13 ms 31684 KB Output is correct
3 Correct 13 ms 31672 KB Output is correct
4 Correct 14 ms 31760 KB Output is correct
5 Correct 15 ms 31672 KB Output is correct
6 Correct 14 ms 31764 KB Output is correct
7 Correct 14 ms 31724 KB Output is correct
8 Correct 15 ms 31692 KB Output is correct
9 Correct 15 ms 31664 KB Output is correct
10 Correct 14 ms 31732 KB Output is correct
11 Correct 14 ms 31792 KB Output is correct
12 Correct 14 ms 31748 KB Output is correct
13 Correct 14 ms 31692 KB Output is correct
14 Correct 14 ms 31728 KB Output is correct
15 Correct 15 ms 31692 KB Output is correct
16 Correct 14 ms 31692 KB Output is correct
17 Correct 14 ms 31692 KB Output is correct
18 Correct 14 ms 31732 KB Output is correct
19 Correct 15 ms 31780 KB Output is correct
20 Correct 14 ms 31688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31692 KB Output is correct
2 Correct 13 ms 31684 KB Output is correct
3 Correct 13 ms 31672 KB Output is correct
4 Correct 14 ms 31760 KB Output is correct
5 Correct 15 ms 31672 KB Output is correct
6 Correct 14 ms 31764 KB Output is correct
7 Correct 14 ms 31724 KB Output is correct
8 Correct 15 ms 31692 KB Output is correct
9 Correct 15 ms 31664 KB Output is correct
10 Correct 14 ms 31732 KB Output is correct
11 Correct 14 ms 31792 KB Output is correct
12 Correct 14 ms 31748 KB Output is correct
13 Correct 14 ms 31692 KB Output is correct
14 Correct 14 ms 31728 KB Output is correct
15 Correct 15 ms 31692 KB Output is correct
16 Correct 14 ms 31692 KB Output is correct
17 Correct 14 ms 31692 KB Output is correct
18 Correct 14 ms 31732 KB Output is correct
19 Correct 15 ms 31780 KB Output is correct
20 Correct 14 ms 31688 KB Output is correct
21 Correct 15 ms 31692 KB Output is correct
22 Correct 16 ms 31692 KB Output is correct
23 Correct 16 ms 31692 KB Output is correct
24 Correct 31 ms 31692 KB Output is correct
25 Correct 30 ms 31692 KB Output is correct
26 Correct 30 ms 31692 KB Output is correct
27 Correct 30 ms 31692 KB Output is correct
28 Correct 23 ms 31692 KB Output is correct