#include <bits/stdc++.h>
#define N 10001
using namespace std;
typedef long long ll;
int n, k, v[N], tot, used[N], mod = 1000007;
int dp[2][N], pref[N];
int solve(int i, int k)
{
if(i > n) return 1;
if(dp[i][k] != -1) return dp[i][k];
ll A = (((ll)solve(i + 1, k) * (ll)k) % mod + solve(i + 1, k + 1) % mod)%mod;
return dp[i][k] = A;
}
inline ll pos()
{
set<int> add;
for(int i = 1; i <= n; i++)
{
pref[i] = add.size();
add.insert(v[i]);
}
int A = (n + 1)%2, B = n%2;
for(int i = n + 1; i >= 1; i--)
{
for(int k = n; k >= 1; k--)
{
if(i > n) dp[A][k] = 1;
else
{
dp[A][k] = ( (ll)k * dp[B][k] + dp[B][k + 1])%mod;
}
}
if(i <= n) tot = (tot + dp[B][ pref[i] ]*(v[i] - 1LL) )%mod;
swap(A, B);
}
return (tot + 1)%mod;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for(int i = 1; i <= n; i++) cin>>v[i];
cout<<pos()<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
3 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
612 KB |
Output is correct |
2 |
Correct |
3 ms |
612 KB |
Output is correct |
3 |
Correct |
3 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
2 |
Correct |
3 ms |
624 KB |
Output is correct |
3 |
Correct |
3 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
624 KB |
Output is correct |
2 |
Correct |
3 ms |
624 KB |
Output is correct |
3 |
Correct |
3 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
624 KB |
Output is correct |
2 |
Correct |
7 ms |
624 KB |
Output is correct |
3 |
Correct |
9 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
624 KB |
Output is correct |
2 |
Correct |
18 ms |
624 KB |
Output is correct |
3 |
Correct |
25 ms |
624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
1132 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
385 ms |
1132 KB |
Output is correct |
2 |
Correct |
402 ms |
1132 KB |
Output is correct |
3 |
Correct |
366 ms |
1132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
1132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |