#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 f[nmax];
ll inv[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;
for(int i = 1 ;i <= n; ++i){
c[i] = 1;
for(int j = i - 1; j >= 2 ;j--)
c[j] += c[j - 1], c[j] %= mod;
if(i != 1){
po[0] = 1;
ll k= st.size();
for(int j = 1; j <= n; 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;
}
st.insert(a[i]);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
472 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
510 ms |
544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1068 ms |
828 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |