#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
const ll mod=1000007;
ll power(int a, int b){
if (b==0) return 1;
ll sol=power(a,b/2)%mod;
sol=sol*sol%mod;
if (b%2) sol*=a;
cerr << a <<' '<<b<<' '<<sol<<'\n';
return sol%mod;
}
int main(){
int n;
cin >> n;
vvi sol(n+1,vi(n+1,1)); //sol[n][x]
for (int i=1;i<=n;i++) sol[1][i]=i+1;
for (int i=2;i<=n;i++){
for (int j=1;j<=n-i+1;j++) sol[i][j]=(j*sol[i-1][j]+sol[i-1][j+1])%mod;
}
vi v(n);
for (int i=n-1;i>=0;i--) cin >> v[i];
ll res=0;
ll maxvisto=0;
for (int i=n-1;i>=0;i--){
res+=(v[i]-1)*sol[i][maxvisto]%mod;
maxvisto=max(v[i],maxvisto);
//cerr << i << ' ' << v[i] <<' '<< res << '\n';
}
cout <<(res+1)%mod<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2252 KB |
Output is correct |
2 |
Correct |
2 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8140 KB |
Output is correct |
2 |
Correct |
6 ms |
8076 KB |
Output is correct |
3 |
Correct |
7 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
39 ms |
65540 KB |
Execution killed with signal 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
39 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
37 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |