Submission #1116258

#TimeUsernameProblemLanguageResultExecution timeMemory
1116258vjudge1Calvinball championship (CEOI15_teams)C++17
100 / 100
336 ms840 KiB
#include <bits/stdc++.h> using i64 = long long; #ifdef DEBUG #include "/home/ahmetalp/Desktop/Workplace/debug.h" #else #define debug(...) void(23) #endif template<typename T> T power(T a, i64 b) { T res = 1; while(b) { if(b & 1) { res *= a; } a *= a; b >>= 1; } return res; } constexpr int md = int(1E6) + 7; struct MInt { int val; MInt() : val(0) {} template<typename T> MInt(T v) { if(-md <= v && v < md) { val = v; } else { val = v % md; } if(val < 0) { val += md; } } int operator() () { return val; } MInt operator+= (MInt rhs) { if((val += rhs.val) >= md) { val -= md; } return *this; } MInt operator-= (MInt rhs) { if((val -= rhs.val) < 0) { val += md; } return *this; } MInt operator*= (MInt rhs) { val = (int)(1LL * val * rhs.val % md); return *this; } MInt inv() { return power(*this, md - 2); } MInt operator/= (MInt rhs) { return *this *= rhs.inv(); } bool operator== (MInt rhs) { return val == rhs.val; } bool operator!= (MInt rhs) { return val != rhs.val; } }; MInt operator+ (MInt lhs, MInt rhs) { return lhs += rhs; } MInt operator- (MInt lhs, MInt rhs) { return lhs -= rhs; } MInt operator* (MInt lhs, MInt rhs) { return lhs *= rhs; } MInt operator/ (MInt lhs, MInt rhs) { return lhs /= rhs; } std::ostream& operator<< (std::ostream& os, MInt v) { return os << v(); } std::string to_string(MInt x) { return to_string(x()); } using Z = MInt; constexpr int max_N = int(1E4) + 5; int N, A[max_N]; Z dp[2][2][max_N]; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cin >> N; for (int i = 0; i < N; ++i) { std::cin >> A[i]; } dp[0][0][0] = 1; for (int i = 0; i < N; ++i) { for (int j = 0; j < max_N; ++j) { dp[1][0][j] = dp[1][1][j] = 0; } for (int j = 0; j <= N; ++j) { if (dp[0][0][j] != 0) { dp[1][1][j] += dp[0][0][j] * std::max(0, std::min(A[i] - 1, j)); if (j + 1 >= A[i]) { dp[1][0][std::max(j, A[i])] += dp[0][0][j]; } } if (dp[0][1][j] != 0) { dp[1][1][j] += dp[0][1][j] * j; dp[1][1][j + 1] += dp[0][1][j]; } } std::swap(dp[0], dp[1]); } Z ans = 0; for (int i = 0; i <= N; ++i) { ans += dp[0][0][i] + dp[0][1][i]; } std::cout << ans << '\n'; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...