#include <bits/stdc++.h>
#define N 1001
using namespace std;
typedef long long ll;
ll n, k, v[N], tot, used[N], mod = 1000007;
int dp[N][N];
ll solve(ll i, ll k)
{
if(i > n) return 1;
if(dp[i][k] != -1) return dp[i][k];
ll A = ((solve(i + 1, k) * k) % mod + solve(i + 1, k + 1) % mod)%mod;
return dp[i][k] = A;
}
inline ll pos()
{
set<ll> add;
ll q;
memset(dp, -1, sizeof dp);
for(ll i = 1; i <= n; i++)
{
tot = (tot + solve(i + 1, add.size())*(v[i] - 1) )%mod;
add.insert(v[i]);
}
return (tot + 1)%mod;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
ll s = 0;
for(ll i = 1; i <= n; i++)
{
cin>>v[i];
if(!used[v[i]]) k++;
used[v[i]] = 1;
s = (s + solve(n, i))%mod;
}
cout<<pos()<<"\n";
}
Compilation message
teams.cpp: In function 'll pos()':
teams.cpp:25:5: warning: unused variable 'q' [-Wunused-variable]
ll q;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4216 KB |
Output is correct |
2 |
Correct |
5 ms |
4216 KB |
Output is correct |
3 |
Correct |
5 ms |
4360 KB |
Output is correct |
4 |
Correct |
7 ms |
4360 KB |
Output is correct |
5 |
Correct |
6 ms |
4360 KB |
Output is correct |
6 |
Correct |
7 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4464 KB |
Output is correct |
2 |
Correct |
7 ms |
4464 KB |
Output is correct |
3 |
Correct |
7 ms |
4516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4516 KB |
Output is correct |
2 |
Correct |
7 ms |
4516 KB |
Output is correct |
3 |
Correct |
7 ms |
4516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4516 KB |
Output is correct |
2 |
Correct |
7 ms |
4516 KB |
Output is correct |
3 |
Correct |
7 ms |
4516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
4576 KB |
Output is correct |
2 |
Correct |
15 ms |
4576 KB |
Output is correct |
3 |
Correct |
15 ms |
4604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
4608 KB |
Output is correct |
2 |
Correct |
48 ms |
4744 KB |
Output is correct |
3 |
Correct |
37 ms |
4744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
4744 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
4744 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
4744 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |