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

#TimeUsernameProblemLanguageResultExecution timeMemory
115965IOrtroiiiKangaroo (CEOI16_kangaroo)C++14
100 / 100
27 ms14208 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2020; const int mod = 1000000007; int f[N][N]; void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } int mul(int x, int y) { return (long long) x * y % mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, cs, cf; cin >> n >> cs >> cf; f[1][1] = 1; for (int i = 2; i <= n; ++i) { for (int j = 1; j < i; ++j) { if (i == cs || i == cf) { add(f[i][j], f[i - 1][j]); add(f[i][j + 1], f[i - 1][j]); } else { if (j >= 2) add(f[i][j - 1], mul(f[i - 1][j], j - 1)); int k = j - (i > cs) - (i > cf) + 1; add(f[i][j + 1], mul(f[i - 1][j], k)); } } } cout << f[n][1] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...