Submission #258990

#TimeUsernameProblemLanguageResultExecution timeMemory
258990Haunted_CppCalvinball championship (CEOI15_teams)C++17
40 / 100
665 ms584 KiB
/** * author: Haunted_Cpp **/ #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__) #else #define debug(...) 47 #endif const int N = 1e4 + 5; const int MOD = 1e6 + 7; int dp[2][N][2]; int add(int a, int b) { int res = a + b; if (res >= MOD) res -= MOD; return res; } int mult(int a, int b) { long long res = 1LL * a * b; if (res >= MOD) res %= MOD; return res; } int main () { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 1; i < arr[0]; i++) { dp[0][i][1] = 1; } dp[0][arr[0]][0] = 1; for (int i = 1; i < n; i++) { for (int j = 1; j <= n; j++) { dp[i & 1][j][1] = add(dp[i & 1][j][1], dp[(i - 1) & 1][j - 1][1]); dp[i & 1][j][1] = add(dp[i & 1][j][1], mult(dp[(i - 1) & 1][j][1], j)); if (j < arr[i]) { dp[i & 1][j][1] = add(dp[i & 1][j][1], dp[(i - 1) & 1][j - 1][0]); dp[i & 1][j][1] = add(dp[i & 1][j][1], mult(dp[(i - 1) & 1][j][0], j)); } else { if (j == arr[i]) dp[i & 1][j][0] = add(dp[i & 1][j][0], dp[(i - 1) & 1][j - 1][0]); dp[i & 1][j][0] = add(dp[i & 1][j][0], mult(dp[(i - 1) & 1][j][0], min(j, arr[i]))); } } for (int j = 1; j <= n; j++) dp[(i + 1) & 1][j][0] = dp[(i + 1) & 1][j][1] = 0; } int res = 0; for (int i = 1; i <= n; i++) { res = add(res, dp[(n - 1) & 1][i][0]); res = add(res, dp[(n - 1) & 1][i][1]); } cout << res << '\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...