#include <iostream>
using namespace std;
using ll = long long;
const int mod = 1e6 + 7;
const int nmax = 1e4 + 2;
ll dp[2][nmax];
ll a[nmax];
int main()
{
ll n; cin >> n;
ll maxx = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
for (int k = n; k > 0; k--)
{
dp[i%2][k] = dp[(i-1)%2][k-1] + dp[(i-1)%2][k] * k;
// cout << i << ' ' << k << ' ' << dp[i % 2][k] << '\n';
dp[i%2][k] %= mod;
}
dp[i%2][maxx] += a[i] - 1;
dp[i%2][maxx] %= mod;
maxx = max(maxx , a[i]);
}
ll ans = 0;
for (int i = 1; i <= n; i++)
{
ans += dp[n % 2][i];
ans %= mod;
}
cout << (ans + 1) % mod << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
312 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
400 KB |
Output is correct |
2 |
Correct |
45 ms |
460 KB |
Output is correct |
3 |
Correct |
47 ms |
416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
186 ms |
588 KB |
Output is correct |
2 |
Correct |
194 ms |
540 KB |
Output is correct |
3 |
Correct |
191 ms |
552 KB |
Output is correct |