이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define sqr(a) (1LL * (a) * (a))
using namespace std;
#ifdef LOCAL
#include <bug.h>
#else
#define mt(...)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
// https://oj.uz/problem/view/CEOI16_kangaroo
// https://github.com/stefdasca/CompetitiveProgramming/blob/master/CEOI/CEOI%2016-Kangaroo.cpp
// https://codeforces.com/blog/entry/47764?#comment-704139
//-----------------------------------------------------------------------//
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, s, e;
cin >> n >> s >> e;
vector<vector<int>> dp(n + 1, vector<int>(n + 1));
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
if (i == s || i == e) {
dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
}
else {
int a = 1LL * dp[i - 1][j + 1] * j % mod; // merge two components
int subtract = 0;
if (i > s) ++subtract;
if (i > e) ++subtract;
int b = 1LL * dp[i - 1][j - 1] * (j - subtract) % mod; // create new component
dp[i][j] = a + b;
}
dp[i][j] %= mod;
}
}
cout << dp[n][1] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |