Submission #851480

#TimeUsernameProblemLanguageResultExecution timeMemory
851480Nhoksocqt1Calvinball championship (CEOI15_teams)C++17
100 / 100
227 ms1320 KiB
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define sz(x) int((x).size()) #define fi first #define se second typedef long long ll; typedef pair<int, int> ii; template<class X, class Y> inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);} template<class X, class Y> inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int Random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } const int MAXN = 10004; const int MOD = 1000007; ll dp[2][MAXN][2]; int a[MAXN], nArr; ll powermod(ll a, int exponent) { ll res(1); while(exponent > 0) { if(exponent & 1) res = res * a % MOD; a = a * a % MOD; exponent >>= 1; } return res; } void process() { cin >> nArr; for (int i = 1; i <= nArr; ++i) cin >> a[i]; dp[1][1][0] = 1; for (int i = 2; i <= nArr; ++i) { int cur(i & 1), pre(!cur); for (int j = 1; j < i; ++j) { for (int smaller = 0; smaller < 2; ++smaller) { if(!dp[pre][j][smaller]) continue; if(!smaller) { dp[cur][j][1] = (dp[cur][j][1] + dp[pre][j][smaller] * min(j, a[i] - 1)) % MOD; dp[cur][j][0] = (dp[cur][j][0] + dp[pre][j][smaller] * (j >= a[i])) % MOD; } else { dp[cur][j][smaller] = (dp[cur][j][smaller] + dp[pre][j][smaller] * j) % MOD; } if((smaller || j + 1 <= a[i]) && (dp[cur][j + 1][smaller | (j + 1 < a[i])] += dp[pre][j][smaller]) >= MOD) dp[cur][j + 1][smaller | (j + 1 < a[i])] -= MOD; dp[pre][j][smaller] = 0; } } } ll res(0); for (int j = 1; j <= nArr; ++j) res += dp[nArr & 1][j][0] + dp[nArr & 1][j][1]; cout << res % MOD << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); process(); 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...