#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
int main(){
cin.sync_with_stdio(false);
ll n;
cin>>n;
vi v(n);
rep(i,0,n) cin>>v[i];
vector<pii> ansTerms(n+1);
ll numTeams = 1;
rep(i,0,n){
ansTerms[n-i-1] = {v[i]-1,numTeams};
//ans = (ans + (v[i]-1)*dp[n-i-1][numTeams])%mod;
numTeams = max(v[i],numTeams);
}
ll mod = 1e6+7;
ll ans = 0;
vector<ll> dpLast(n+1,1);
ans = (ans + ansTerms[0].first*dpLast[ansTerms[0].second])%mod;
rep(left,1,n+1){
vector<ll> dpNew(n-left+1);
rep(numTeams,1,n-left+1)
dpNew[numTeams] = (numTeams*dpLast[numTeams] + dpLast[numTeams+1])%mod;
ans = (ans + ansTerms[left].first*dpNew[ansTerms[left].second])%mod;
dpLast = dpNew;
}
cout<<(ans+1)%mod<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
616 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
3 ms |
616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
744 KB |
Output is correct |
2 |
Correct |
2 ms |
744 KB |
Output is correct |
3 |
Correct |
2 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
744 KB |
Output is correct |
2 |
Correct |
3 ms |
744 KB |
Output is correct |
3 |
Correct |
4 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
744 KB |
Output is correct |
2 |
Correct |
2 ms |
744 KB |
Output is correct |
3 |
Correct |
3 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
744 KB |
Output is correct |
2 |
Correct |
5 ms |
744 KB |
Output is correct |
3 |
Correct |
5 ms |
744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
190 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
1032 KB |
Output is correct |
2 |
Correct |
48 ms |
1032 KB |
Output is correct |
3 |
Correct |
50 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
1032 KB |
Output is correct |
2 |
Correct |
200 ms |
1132 KB |
Output is correct |
3 |
Correct |
245 ms |
1132 KB |
Output is correct |