#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<vi> dp(n+1,vi(n+1,1));
ll mod = 1e6+7;
rep(left,1,n+1)
rep(numTeams,0,n)
dp[left][numTeams] = (numTeams*dp[left-1][numTeams] + dp[left-1][numTeams+1])%mod;
ll numTeams = 1;
ll ans = 0;
rep(i,0,n){
ans = (ans + (v[i]-1)*dp[n-i-1][numTeams])%mod;
numTeams = max(v[i],numTeams);
}
cout<<(ans+1)%mod<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
644 KB |
Output is correct |
6 |
Correct |
3 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
660 KB |
Output is correct |
2 |
Correct |
2 ms |
660 KB |
Output is correct |
3 |
Correct |
2 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
660 KB |
Output is correct |
2 |
Correct |
3 ms |
660 KB |
Output is correct |
3 |
Correct |
3 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
660 KB |
Output is correct |
2 |
Correct |
2 ms |
660 KB |
Output is correct |
3 |
Correct |
3 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2540 KB |
Output is correct |
2 |
Correct |
5 ms |
2540 KB |
Output is correct |
3 |
Correct |
5 ms |
2540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
8432 KB |
Output is correct |
2 |
Correct |
14 ms |
8432 KB |
Output is correct |
3 |
Correct |
14 ms |
8432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
688 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1020 ms |
66560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
617 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |