# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1273628 | raadbuet | Kangaroo (CEOI16_kangaroo) | C++20 | 20 ms | 23372 KiB |
#include <bits/stdc++.h>
#include <bits/extc++.h> // gp_hash_table, pbds
using namespace __gnu_pbds;
#include<numeric>
using namespace std;
using ll = long long;
#define int ll
using ld = long double;
using vi = vector<int>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using pll = pair<ll, ll>;
using pi = pair<int, int>;
#define f first
#define s second
#define mp make_pair
#define deb false
#define INF 1e18
#define mod1 1000000007
#define mod2 998244353
#define N 100001
#define logN 22
#define endl "\n"
#define hash1 10007
#define hash2 1009
#define rep(i, a, b) for (int i = a; i <= b; ++i)
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int tc = 1, t = 1;
long long binpow(long long a, long long b, long long m) {
long long res = 1;
while (b > 0) {
if (b & 1)
res = (res * a) % m;
a = (a * a) % m;
b >>= 1;
}
return res % m;
}
long long compute_hash(string const& s) {
const int p = 31;
const int m = 1e9 + 9;
long long hash_value = 0;
long long p_pow = 1;
for (char c : s) {
hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
p_pow = (p_pow * p) % m;
}
return hash_value;
}
int dp[2001][2001];
void solve() {
int n, cs, cf;
cin >> n >> cs >> cf;
if (cs > cf) swap(cs, cf);
dp[1][1] = 1;
for (int i = 1; i <= n - 1; i++) {
for (int j = 1; j <= i; j++) {
if (i + 1 > cf) {
dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * (j - 1)) % mod1;
dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * (j - 1)) % mod1;
} else if (i + 1 == cf) {
dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod1;
dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod1;
} else if (i + 1 > cs) {
dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * j) % mod1;
dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * (j - 1)) % mod1;
} else if (i + 1 == cs) {
dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod1;
dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod1;
} else {
dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * (j + 1)) % mod1;
dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * (j - 1)) % mod1;
}
}
}
cout << dp[n][1] << endl;
}
int32_t main() {
fast;
//cin >> t;
//preproces();
freopen("kangaroo.in", "r", stdin);
freopen("kangaroo.out", "w", stdout);
for (tc = 1; tc <= t; tc++) {
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |