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

#TimeUsernameProblemLanguageResultExecution timeMemory
470372hoanghq2004Kangaroo (CEOI16_kangaroo)C++14
100 / 100
22 ms14028 KiB
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int Nmax = 2010; int n; int S, T; int f[Nmax][Nmax]; int main() { cin >> n >> S >> T; f[1][1] = 1; for (int i = 1; i < n; ++i) { for (int j = 1; j <= i; ++j) { if (f[i][j] == 0) continue; if (i + 1 == S || i + 1 == T) { f[i + 1][j] += f[i][j]; f[i + 1][j + 1] += f[i][j]; if (f[i + 1][j] >= mod) f[i + 1][j] -= mod; if (f[i + 1][j + 1] >= mod) f[i + 1][j + 1] -= mod; } else { f[i + 1][j - 1] += 1LL * f[i][j] * (j - 1) % mod; if (f[i + 1][j - 1] >= mod) f[i + 1][j - 1] -= mod; f[i + 1][j + 1] += 1LL * (j + 1 - (i + 1 > S) - (i + 1 > T)) * f[i][j] % mod; if (f[i + 1][j + 1] >= mod) f[i + 1][j + 1] -= mod; } } } cout << f[n][1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...