# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
280357 | thtsshz_bgwrswh | Calvinball championship (CEOI15_teams) | C++17 | 739 ms | 764 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
long long dp[2][10005]={0},num[10005],pre[10005]={0},mod=1000007;
int main(){
long long i,j,n;
scanf("%lld",&n);
for(i=1;i<=n;i++)
scanf("%lld",&num[i]);
pre[1]=num[1];
for(i=2;i<=n;i++)
pre[i]=max(pre[i-1],num[i]);
long long cur=0,ans=num[n];
for(i=1;i<=n;i++)
dp[cur][i]=i+1;
for(i=n-1;i>=1;i--){
if(pre[i-1]>=num[i]-1)
ans=(ans+dp[cur][pre[i-1]]*(num[i]-1))%mod;
else{
ans=(ans+dp[cur][pre[i-1]]*pre[i-1])%mod;
for(j=pre[i-1]+1;j<num[i];j++)
ans+=dp[cur][j];
ans%=mod;
}
//for(j=1;j<num[i];j++)
// ans=(ans+dp[cur][max(pre[i-1],j)])%mod;
cur^=1;
for(j=1;j<=n;j++)
dp[cur][j]=(dp[cur^1][j]*j+dp[cur^1][j+1])%mod;
}
printf("%lld\n",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |