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

#TimeUsernameProblemLanguageResultExecution timeMemory
243539tonowakKangaroo (CEOI16_kangaroo)C++17
0 / 100
5 ms384 KiB
#include <bits/stdc++.h> // Tomasz Nowak using namespace std; // XIII LO Szczecin using LL = long long; // Poland #define FOR(i, l, r) for(int i = (l); i <= (r); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) template<class T> int size(T &&x) { return int(x.size()); } template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) { return out << '(' << p.first << ", " << p.second << ')'; } template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) { out << '{'; for(auto it = x.begin(); it != x.end(); ++it) out << *it << (it == prev(x.end()) ? "" : ", "); return out << '}'; } void dump() {} template<class T, class... Args> void dump(T &&x, Args... args) { cerr << x << "; "; dump(args...); } #ifdef DEBUG struct Nl{~Nl(){cerr << '\n';}}; # define debug(x...) cerr << (strcmp(#x, "") ? #x ": " : ""), dump(x), Nl(), cerr << "" #else # define debug(...) 0 && cerr #endif mt19937_64 rng(0); int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } // end of templates constexpr int mod = int(1e9) + 7; int add(int a, int b) { a += b; if(a >= mod) a -= mod; return a; } int mul(int a, int b) { return int(a * LL(b) % mod); } int& add_to(int &a, int b) { return a = add(a, b); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, start, end; cin >> n >> start >> end; vector<vector<array<int, 3>>> dp(n + 1, vector<array<int, 3>>(n, array<int, 3>{{0, 0, 0}})); dp[0][0][0] = 1; auto choose2 = [&](int cnt) { return int((cnt * LL(cnt - 1) / 2) % mod); }; FOR(i, 1, n) FOR(open, 0, n - 1) { if(i == start or i == end) { add_to(dp[i][open][1], dp[i - 1][open][0]); add_to(dp[i][open][2], dp[i - 1][open][1]); if(open + 1 < n) { add_to(dp[i][open][1], dp[i - 1][open + 1][0]); add_to(dp[i][open][2], dp[i - 1][open + 1][1]); } } else { if(open + 1 < n) { add_to(dp[i][open][0], mul(dp[i - 1][open + 1][0], choose2(open + 1))); add_to(dp[i][open][1], mul(dp[i - 1][open + 1][1], choose2(open + 1))); add_to(dp[i][open][2], mul(dp[i - 1][open + 1][2], choose2(open + 1))); add_to(dp[i][open][0], dp[i - 1][open][2]); } if(open >= 1) { add_to(dp[i][open][0], dp[i - 1][open - 1][0]); add_to(dp[i][open][1], dp[i - 1][open - 1][1]); add_to(dp[i][open][2], dp[i - 1][open - 1][2]); } } } FOR(i, 1, n) FOR(open, 0, n - 1) debug(i, open, dp[i][open]); cout << dp[n][0][0] << '\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...