#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
const int N = 3e5 + 5;
const int mod = 1e6 + 7;
const int oo = 2e9;
typedef long long ll;
typedef pair<int,int> pii;
int main() {
#ifdef LOCAL
freopen("input.txt","r",stdin);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
vector <int> a(n);
for (auto &e : a) cin >> e;
vector <int> ask (n, 0);
for (int i = 2; i < n; ++i) {
ask[i] = max(a[i - 2], ask[i - 1]);
}
vector <vector <int>> dp (2, vector<int>(n + 1, 0));
vector <int> sv (n + 1, 0);
sv[n]=1;
for (int j = 1; j <= n; ++j) dp[n & 1][j] = 1;
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j < n; ++j) {
dp[i & 1][j] = (1ll * dp[(i + 1) & 1][j] * j + dp[(i + 1) & 1][j + 1]) % mod;
}
sv[i] = dp[i & 1][ask[i]];
}
int ans = 0;
for (int i = 0; i < n; ++i) {
ans = (1ll * ans + 1ll * sv[i + 1] * (a[i] - 1)) % mod;
}
cout << (ans + 1)%mod << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
344 KB |
Output is correct |
2 |
Correct |
39 ms |
344 KB |
Output is correct |
3 |
Correct |
39 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
660 KB |
Output is correct |
2 |
Correct |
157 ms |
604 KB |
Output is correct |
3 |
Correct |
155 ms |
676 KB |
Output is correct |