#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for (int i=1;i<=n;i++)
#define REP(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define mp make_pair
#define sz(x) ((int)(x).size())
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll linf=1e18;
const int N=10000+1;
const double eps=1e-5;
const int mo=1e6+7;
int n;
int a[N];
int g[2][N];
int f[N][2];
int dp[N];
bool fi[N];
int mx[N];
int ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&n);
FOR(i,n) scanf("%d",&a[i]);
FOR(i,n) {
mx[i]=mx[i-1];
if (a[i]>mx[i]) {
fi[i]=1;
mx[i]=a[i];
}
}
int tot,pre;
f[0][1]=f[0][0]=1;
tot=mx[n];
for (int i=n;i>=tot+1;i--) {
f[1][i%2]=1;
REP(j,2,n) f[j][i%2]=((ll)f[j-1][(i+1)%2]%mo+(ll)i*f[j-1][i%2]%mo)%mo;
}
g[tot%2][0]=1;
FOR(i,n) g[tot%2][i]=(ll)g[tot%2][i-1]*tot%mo;
for (int i=n;i>=1;i--) {
tot=mx[i];
pre=tot;
if (fi[i]) pre--;
/*
g[tot%2][0]=1;
FOR(i,n) g[tot%2][i]=(ll)g[tot%2][i-1]*tot%mo;
*/
if (i==n||mx[i]!=mx[i+1]) {
g[(tot-1)%2][0]=1;
FOR(i,n) g[(tot-1)%2][i]=(ll)g[(tot-1)%2][i-1]*(tot-1)%mo;
f[1][tot%2]=1;
REP(i,2,n) f[i][tot%2]=((ll)f[i-1][(tot+1)%2]%mo+(ll)tot*f[i-1][tot%2]%mo)%mo;
}
if (a[i]>1) {
if (tot==pre) FOR(j,n-i+1) {
if (tot+1<=n) dp[i]+=(ll)(a[i]-1)*g[tot%2][j-1]%mo*f[n-i-j+1][(tot+1)%2]%mo,dp[i]%=mo;
else if (j==n-i+1) dp[i]+=(ll)(a[i]-1)*g[tot%2][j-1]%mo*1%mo,dp[i]%=mo;
} else {
FOR(j,n-i+1) {
dp[i]+=(ll)(a[i]-1)*g[pre%2][j-1]%mo*f[n-i-j+1][tot%2]%mo,dp[i]%=mo;
}
}
}
//cout<<dp[i]<<endl;
ans+=dp[i];
ans%=mo;
}
ans=(ans+1)%mo;
printf("%d\n",ans);
return 0;
}
Compilation message
teams.cpp: In function 'int main()':
teams.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
teams.cpp:38:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
FOR(i,n) scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
556 KB |
Output is correct |
6 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
2 |
Correct |
2 ms |
636 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
636 KB |
Output is correct |
2 |
Correct |
7 ms |
636 KB |
Output is correct |
3 |
Correct |
7 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
636 KB |
Output is correct |
2 |
Correct |
18 ms |
764 KB |
Output is correct |
3 |
Correct |
24 ms |
764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1070 ms |
1028 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
397 ms |
1028 KB |
Output is correct |
2 |
Correct |
421 ms |
1028 KB |
Output is correct |
3 |
Correct |
563 ms |
1028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1081 ms |
1028 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |