This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define pii pair<int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define f first
#define s second
#define oo 1000000001
#define eb emplace_back
#define pb push_back
#define mpr make_pair
#define size(v) (int)v.size()
#define ln '\n'
#define ull unsigned long long
#define ll long long
#define all(v) v.begin(), v.end()
#define iospeed ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//#define pbase 361549
//#define imod 1073737591
//#define uimod 2147479307u
//#define llmod 292187309552789533ll
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
void show(vector<T> &v) {
for (T i : v) {
cout << i << ' ';
}
cout << ln;
}
void solve() {
int n;
cin >> n;
vi a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
vvi dp(n + 1, vi(n + 1, 0));
for (int i = 1; i <= n; ++i) {
dp[n][i] = 1;
}
const int mod = 1e6 + 7;
for (int i = n - 1; i >= 1; --i) {
for (int m = 1; m <= i; ++m) {
dp[i][m] = (1ll * m * dp[i + 1][m] + dp[i + 1][m + 1]) % mod;
}
}
int res = 1;
int m = a[1];
for (int i = 2; i <= n; ++i) {
res = (1ll * (a[i] - 1) * dp[i][m] + res) % mod;
m = max(m, a[i]);
}
cout << res << ln;
}
int main() {
iospeed;
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |