(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #488126

#TimeUsernameProblemLanguageResultExecution timeMemory
488126DrearyJokeKangaroo (CEOI16_kangaroo)C++17
100 / 100
30 ms31692 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ff first #define ss second #define pb push_back #define mp make_pair #define END "\n" #define rall(v) (v).rbegin(), (v).rend() #define all(v) (v).begin(), (v).end() #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; constexpr ll modu = 1e9 + 7; void solve(){ int n, a, b; cin >> n >> a >> b; if (a > b) swap(a, b); vector<vector<ll>> dp(n + 1, vector<ll>(n + 2)); dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (i == a || i == b) dp[i][j] += dp[i - 1][j - 1] + dp[i - 1][j]; else { if (i < a && i < b) { dp[i][j] += (j * (dp[i - 1][j + 1] + dp[i - 1][j - 1])); } else if (i > a && i < b) { dp[i][j] += (j - 1) * (dp[i - 1][j + 1] + dp[i - 1][j - 1]) + dp[i - 1][j + 1]; } else { dp[i][j] += (j - 2) * (dp[i - 1][j + 1] + dp[i - 1][j - 1]) + 2 * dp[i - 1][j + 1]; } } dp[i][j] %= modu; } } cout << dp[n][1] << END; } int main() { fastio int t = 1; // cin>> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...