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

#TimeUsernameProblemLanguageResultExecution timeMemory
393923KhaledFarhatKangaroo (CEOI16_kangaroo)C++14
100 / 100
29 ms16072 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int Add(int x, int y) { return (x + y) % MOD; } void Increase(int& x, int y) { x = Add(x, y); } int Multiply(int x, int y) { return 1LL * x * y % MOD; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, startPosition, finishPosition; cin >> n >> startPosition >> finishPosition; vector<vector<int>> ways(n + 2, vector<int>(n + 1)); ways[2][1] = 1; for (int i = 2; i <= n; ++i) { for (int components = 1; components < i; ++components) { if (ways[i][components] == 0) { continue; } if (i == startPosition || i == finishPosition) { Increase(ways[i + 1][components + 1], ways[i][components]); // open a new component on the side Increase(ways[i + 1][components], ways[i][components]); // append to the side } else { // create a new component int validPosition = (components + 1) - (i > startPosition) - (i > finishPosition); Increase(ways[i + 1][components + 1], Multiply(validPosition, ways[i][components])); // merge two component validPosition = components - 1; Increase(ways[i + 1][components - 1], Multiply(validPosition, ways[i][components])); } } } cout << ways[n + 1][1]; 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...