# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
424528 | cpp219 | Calvinball championship (CEOI15_teams) | C++14 | 238 ms | 656 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 optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e4 + 9;
const ll mod = 1e6 + 7;
typedef pair<ll,ll> LL;
ll n,x,ans = 1,a[N],prv[N],dp[N];
ll mx[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin>>n; memset(dp,-1,sizeof(dp));
for (ll i = 1;i <= n;i++) cin>>a[i],mx[i] = max(mx[i - 1],a[i]);
ans += a[n] - 1;
for (ll i = 1;i <= n;i++) dp[i] = i;
for (ll i = n - 1;i > 0;i--){
for (ll i = 1;i <= n;i++) prv[i] = dp[i];
for (ll i = 1;i <= n;i++) dp[i] = ((i - 1)*prv[i] + prv[i + 1])%mod;
ll x = a[i],now = mx[i - 1];
ans += (x - 1)*prv[now + 1]; ans %= mod;
//cout<<(x - 1)*prv[now + 1]<<"x\n";
}
cout<<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... |