#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
#define pii pair<int,int>
using namespace std;
const int nmax = 10001;
ll mod = 1e6 + 7;
ll dp[2][nmax];
ll DP[nmax];
ll c[nmax];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
//fil(2);
int a[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
dp[0][0] = 1;
DP[0] = 1;
c[0] = 1;
for(int i = 1; i <= n ;i++){
for(int j = 1; j <= i ;j++){
dp[1][j] = dp[0][j - 1] + dp[0][j] * (ll)j;
dp[1][j] %= mod;
}
for(int j = 0; j <= n; j++){
dp[0][j] = dp[1][j];
DP[i] += dp[0][j];
DP[i] %= mod;
dp[1][j] = 0;
}
// cout << DP[i] << ' ';
}
set <int> st;
ll po[n + 1];
ll ans = 1;
int val[n + 1];
val[1] = 1;
st.insert(a[1]);
for(int i = 2; i <= n; i++){
st.insert(a[i]);
val[i] = st.size();
}
for(int i = n ;i >= 2; --i){
c[n - i] = 1;
for(int j = n - i - 1; j >= 1 ;j--)
c[j] += c[j - 1], c[j] %= mod;
if(i != 1){
po[0] = 1;
ll k= val[i - 1];
for(int j = 1; j <= n - i; j++)
po[j] = po[j - 1] * k % mod;
ll res = 0;
for(int x = 0; x <= n - i; x++){
res += c[x] * DP[x] * po[n - i - x];
res %= mod;
}
res *= (ll)(a[i] - 1);
res %= mod;
ans += res;
ans %= mod;
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
340 KB |
Output is correct |
2 |
Correct |
21 ms |
392 KB |
Output is correct |
3 |
Correct |
19 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1080 ms |
1228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
476 ms |
548 KB |
Output is correct |
2 |
Correct |
464 ms |
568 KB |
Output is correct |
3 |
Correct |
467 ms |
740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1054 ms |
936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |