제출 #1121678

#제출 시각아이디문제언어결과실행 시간메모리
1121678vjudge1Calvinball championship (CEOI15_teams)C++17
70 / 100
72 ms65536 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define endl "\n" using namespace std; using namespace __gnu_pbds; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T, typename key = less_equal<T>> using ordered_set = tree<T, null_type, key, rb_tree_tag, tree_order_statistics_node_update>; const ll mod = 1e6 + 7; void solve() { ll n; cin >> n; ll a[n + 1]; for (ll i = 1; i <= n; i++) cin >> a[i]; ll dp[n + 1][n + 2][2]; for (ll i = 0; i <= n; i++) for (ll j = 0; j <= n + 1; j++) dp[i][j][0] = dp[i][j][1] = 0; dp[0][1][0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= n; j++) { if (a[i] - j <= 1) dp[i][max(a[i], j)][0] += dp[i - 1][j][0]; dp[i][j][1] += min(j, a[i] - 1) * dp[i - 1][j][0]; if (j + 1 < a[i]) dp[i][j + 1][1] += dp[i - 1][j][0]; dp[i][j][1] += j * dp[i - 1][j][1]; dp[i][j + 1][1] += dp[i - 1][j][1]; } for (ll j = 1; j <= n; j++) dp[i][j][0] %= mod, dp[i][j][1] %= mod; } ll ans = 0; for (ll i = 1; i <= n; i++) ans += dp[n][i][1]; cout << (ans + 1) % mod << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll t = 1; // precomp(); // cin >> t; for (ll cs = 1; cs <= t; cs++) solve(); // cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\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...
#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...