#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e6 + 7;
int n;
vector<int> a;
//vector< vector<ll> > dp;
ll dp[10100][10100];
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
a.resize( n );
for ( auto& el : a )
cin >> el;
//dp.assign( n+1, vector<ll>( n+1, 0 ) );
for ( int i=1; i<=n; i++ )
dp[0][i] = 1;
for ( int i=1; i<=n; i++ )
for ( int j=1; j<=n; j++ )
{
if ( j+1 <= n )
dp[i][j] = ( j*dp[i-1][j] + dp[i-1][j+1] ) % MOD;
else
dp[i][j] = j*dp[i-1][j] % MOD;
}
if ( n > 1000 )
return 0;
ll ans = 1;
int maxi = 0;
for ( int i=0; i<n; i++ )
{
for ( int j=1; j<a[i]; j++ )
ans = ( ans + dp[n-i-1][ max(maxi,j) ] ) % MOD;
maxi = max( maxi, a[i] );
}
cout << ans;
return 0;
}
# |
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 |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
0 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4308 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
3 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12244 KB |
Output is correct |
2 |
Correct |
8 ms |
12244 KB |
Output is correct |
3 |
Correct |
10 ms |
12308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
44 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
43 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
43 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |