#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
const int N = 1e3+5, mod = 1e9+7;
ll n, dp[N][N][2], a[N];
ll sol(int i, ll j, int bit)
{
if(i == n) return 1;
ll &ret = dp[i][j][bit];
if(ret != -1) return ret;
if(bit) ret = j*sol(i+1, j, 1)%mod + sol(i+1, j+1, 1)%mod;
else ret = (a[i]-1)*sol(i+1, max(j, a[i]-1), 1)%mod +
sol(i+1, max(j, a[i]), 0)%mod;
return ret%mod;
}
int main()
{
memset(dp, -1, sizeof dp);
cin >> n;
for(int i=0; i<n; i++) cin >> a[i];
cout << sol(0, 0, 0) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16120 KB |
Output is correct |
2 |
Correct |
15 ms |
16120 KB |
Output is correct |
3 |
Correct |
15 ms |
16120 KB |
Output is correct |
4 |
Correct |
15 ms |
16120 KB |
Output is correct |
5 |
Correct |
15 ms |
16120 KB |
Output is correct |
6 |
Correct |
15 ms |
16120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16120 KB |
Output is correct |
2 |
Correct |
15 ms |
16220 KB |
Output is correct |
3 |
Correct |
15 ms |
16120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
16120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
16120 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
16176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
16120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
16248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
16116 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
16092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
16120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |