#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e4;
const int Mod = 1e9 + 7;
int n;
int v[nmax + 5];
int fact[nmax + 5], invfact[nmax + 5];
int dp[nmax + 5];
int lgput(int a, int b)
{
int p = 1;
while(b)
{
if(b % 2 == 0)
{
b/=2;
a = 1LL * a * a % Mod;
}
else
{
--b;
p = 1LL * p * a % Mod;
}
}
return p;
}
int invmod(int x)
{
return lgput(x,Mod-2);
}
int comb(int n, int k)
{
return 1LL * fact[n] * invfact[k] % Mod * invfact[n - k] % Mod;
}
void precalc()
{
fact[0] = 1;
for(int i=1;i<=nmax;i++)
{
fact[i] = 1LL * fact[i - 1] * i % Mod;
}
invfact[nmax] = invmod(fact[nmax]);
for(int i=nmax-1;i>=0;i--)
{
invfact[i] = 1LL * invfact[i + 1] * (i + 1) % Mod;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>n;
precalc();
for(int i=1;i<=n;i++)
{
cin>>v[i];
}
dp[0] = 1;
for(int i=0;i<=n;i++)
{
for(int nr=1;i+nr<=n;nr++)
{
dp[i + nr] += 1LL * dp[i] * comb(i + nr - 1, nr - 1) % Mod;
dp[i + nr] %= Mod;
}
}
int Max = 0;
long long rez = 0;
for(int i=1;i<=n;i++)
{
if(v[i]==1)
{
Max = max(Max, v[i]);
continue;
}
int nr = v[i] - 1;
for(int nr=0;i+nr<=n;nr++)
{
rez += 1LL * dp[nr] * comb(n - i, nr) % Mod * lgput(Max, n - i - nr) % Mod;
rez %= Mod;
}
Max = max(Max, v[i]);
}
rez = (rez + 1) % Mod;
cout<<rez<<'\n';
return 0;
}
Compilation message
teams.cpp: In function 'int main()':
teams.cpp:90:13: warning: unused variable 'nr' [-Wunused-variable]
90 | int nr = v[i] - 1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1052 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
820 ms |
560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1052 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |