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

#TimeUsernameProblemLanguageResultExecution timeMemory
481293MarkadiuszKangaroo (CEOI16_kangaroo)C++17
100 / 100
37 ms31732 KiB
#include <bits/stdc++.h> using namespace std; using LL=long long; #define FOR(i,l,r) for(int i=(l);i<=(r);++i) #define REP(i,n) FOR(i,0,(n)-1) #define ssize(x) int(x.size()) template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';} template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';} #ifdef DEBUG #define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n' #else #define debug(...) {} #endif int main() { cin.tie(0)->sync_with_stdio(0); const long long mod = 1e9 + 7; int n, cs, cf; cin >> n >> cs >> cf; debug(n, cs, cf); if (cs > cf) { swap(cs, cf); } debug(cs, cf); vector <vector <long long> >dp(n + 1, vector <long long> (n + 1, 0ll)); dp[1][1] = 1; FOR(i, 1, n - 1) { FOR(j, 1, n - 1) { if (i + 1 == cs || i + 1 == cf) { dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod; dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod; } else if (i < cs) { dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * (j + 1)) % mod; dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * (j - 1)) % mod; } else if (i < cf) { dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * j) % mod; dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * (j - 1)) % mod; } else { // i >= cf dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * (j - 1)) % mod; dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j] * (j - 1)) % mod; } } } debug(dp); cout << dp[n][1] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...