# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
457824 | vanic | Calvinball championship (CEOI15_teams) | C++14 | 972 ms | 472 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.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e4+5, mod=1e6+7, Log=20;
int n;
int dp[2][maxn];
inline int sum(int a, int b){
if(a+b>=mod){
return a+b-mod;
}
if(a+b<0){
return a+b+mod;
}
return a+b;
}
inline int mul(int a, int b){
return (ll)a*b%mod;
}
int a[maxn];
int pref[maxn];
int main(){
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%d", a+i);
}
int sol=1;
bool tren=0;
for(int i=0; i<maxn; i++){
dp[1][i]=1;
}
pref[0]=1;
for(int i=0; i<n; i++){
pref[i+1]=max(pref[i], a[i]);
}
for(int i=n-1; i>-1; i--){
sol=sum(sol, mul(a[i]-1, dp[tren^1][pref[i]]));
for(int j=0; j<maxn-1; j++){
dp[tren][j]=sum(mul(j, dp[tren^1][j]), dp[tren^1][j+1]);
}
tren^=1;
}
printf("%d\n", sol);
return 0;
}
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... |