#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define ii pair<ll,ll>
#define endl '\n'
const ll inf=1e15;
const ll mod=1e6+7;
const ll maxn=1005;
int dp[maxn][maxn];
int precom[maxn][maxn];
ll expo(ll n, ll x){
if (precom[n][x]) return precom[n][x];
if (x==0) return 1;
if (x==1) return n;
ll temp=expo(n,x/2);
if (x&1){
return (temp*(temp*n)%mod)%mod;
}
return precom[n][x]=(temp*temp)%mod;
}
ll solve(ll digit, ll rem){
if (rem==0) return 1;
if (dp[digit][rem]!=-1) return dp[digit][rem];
ll ans=0;
for (int i=1;i<=rem;i++){
ans+=solve(digit+1,rem-i)*expo(digit,i-1);
ans%=mod;
}
ans+=expo(digit,rem);
return dp[digit][rem]=ans%mod;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,ele,ans=0;
cin>>n;
ll ele2=0,temp;
memset(dp,-1,sizeof(dp));
for (int i=1;i<=n;i++){
cin>>ele;
for (int j=1;j<ele;j++){
temp=max<ll>(j,ele2);
ans+=solve(temp,n-i);
ans%=mod;
}
ele2=max(ele,ele2);
}
cout<<(ans+1)%mod;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4172 KB |
Output is correct |
2 |
Correct |
2 ms |
4172 KB |
Output is correct |
3 |
Correct |
2 ms |
4176 KB |
Output is correct |
4 |
Correct |
2 ms |
4172 KB |
Output is correct |
5 |
Correct |
2 ms |
4172 KB |
Output is correct |
6 |
Correct |
2 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4172 KB |
Output is correct |
2 |
Correct |
2 ms |
4172 KB |
Output is correct |
3 |
Correct |
2 ms |
4224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4300 KB |
Output is correct |
2 |
Correct |
3 ms |
4300 KB |
Output is correct |
3 |
Correct |
2 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4556 KB |
Output is correct |
2 |
Correct |
4 ms |
4556 KB |
Output is correct |
3 |
Correct |
3 ms |
4556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
6132 KB |
Output is correct |
2 |
Correct |
169 ms |
6216 KB |
Output is correct |
3 |
Correct |
173 ms |
6216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
7884 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1081 ms |
6300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
6360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1076 ms |
6488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |