(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 #486129

#TimeUsernameProblemLanguageResultExecution timeMemory
486129MilosMilutinovicKangaroo (CEOI16_kangaroo)C++14
100 / 100
25 ms19040 KiB
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int add(int x, int y) { x += y; return x >= mod ? x - mod : x; } int mul(int x, int y) { return (long long) (x * y) % mod; } int sub(int x, int y) { x -= y; return x < 0 ? x + mod : x; } const int N = 2005; int a, b, dif, dp[N][N], ft[N][N]; bool was[N][N]; long long Solve(int n, int id) { if (was[n][id]) { return dp[n][id]; } was[n][id] = true; if (id == 1) { return dp[n][id] = ft[n][n - dif]; } else if (id == 2) { return dp[n][id] = add(ft[n][n - dif], ft[n - 1][n - 1 - dif]); } else { return dp[n][id] = sub(sub(mul(2, Solve(n, id - 1)), Solve(n, id - 2)), Solve(n - 2, id - 2)); } } void Precalc(int n) { ft[2][2] = 1; // pocetni slucaj for (int i = 3; i <= n; i++) { if (i % 2 == 1) { int sum = 0; for (int j = 2; j < n; j++) { sum = add(sum, ft[i - 1][j]); } ft[i][2] = add(ft[i][2], sum); } for (int j = 3; j <= i; j++) { if (i % 2 == 1) { ft[i][j] = sub(ft[i][j - 1], ft[i - 1][j - 1]); } else { ft[i][j] = add(ft[i][j - 1], ft[i - 1][j - 1]); } } } } long long resi(int n) { Precalc(n); return Solve(n, a); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n >> a >> b; if (a > b) { swap(a, b); } dif = n - b; cout << resi(n) << '\n'; 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...