#include <bits/stdc++.h>
#define N 10005
using namespace std;
typedef long long ll;
ll n, k, v[N], tot, used[N], mod = 1000007;
ll dp[N][N];
ll solve(ll i, ll k)
{
if(i > n) return 1;
if(dp[i][k] != -1) return dp[i][k];
return dp[i][k] = (solve(i + 1, k) * k + solve(i + 1, k + 1))%mod;
}
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:23:5: warning: unused variable 'q' [-Wunused-variable]
ll q;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
654 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
592 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
711 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
777 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
741 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
669 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
697 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
716 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
739 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
682 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |