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("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4 + 5;
const ll INF = 1e18 + 5;
const ll mod = 1e6 + 7;
const int tx[] = {1, -1, 0, 0}, ty[] = {0, 0, 1, -1};
const ll bs = 31;
#define int ll
int n, a[N], b[N], cnt, res[N], mx[N];
unordered_map <int, int> dp[10005];
int calc(int id, int mx) {
if (dp[id][mx])
return dp[id][mx];
return dp[id][mx] = (mx * calc(id - 1, mx) % mod + calc(id - 1, mx + 1)) % mod;
}
main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
dp[i].reserve(105);
dp[0][i] = 1;
mx[i] = max(mx[i - 1], a[i]);
}
int ans = 0;
for (int i = n - 1; i >= 1; i--) {
ans = (ans + (a[i + 1] - 1) * calc(n - i - 1, mx[i]) % mod) % mod;
}
cout << (ans + 1) % mod;
return 0;
}
/**
5
1 2 1 1 1
*/
Compilation message (stderr)
teams.cpp:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# | 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... |