# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
83539 | nikolapesic2802 | Calvinball championship (CEOI15_teams) | C++14 | 168 ms | 66560 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 <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; ///find_by_order(),order_of_key()
const int N=1e4+5;
const int mod=1e6+7;
int dp[N][N]; /// dp[x][y] Number of ways to choose x numbers if the max so far is y
int pref[N];
int add(int a,int b){
a+=b;
if(a>mod)
a-=mod;
return a;
}
int sub(int a,int b)
{
a-=b;
if(a<0)
a+=mod;
return a;
}
int get(int l,int r)
{
if(l==0)
return pref[r];
return sub(pref[r],pref[l-1]);
}
int main()
{
for(int i=0;i<N;i++)
dp[0][i]=1;
for(int n=1;n<N;n++)
{
pref[0]=dp[n-1][0];
for(int i=1;i<N;i++)
{
pref[i]=add(pref[i-1],dp[n-1][i]);
}
for(int i=0;i<N-1;i++)
{
dp[n][i]=add(((ll)dp[n-1][i]*(i+1))%mod,dp[n-1][i+1]);
}
}
int n;
scanf("%i",&n);
/*vector<int> a(n);
for(int i=0;i<n;i++)
scanf("%i",&a[i]);*/
int res=0;
int tr=0;
for(int i=0;i<n;i++){
int a;
scanf("%i",&a);
//printf("%i %i\n",n-i-1,tr);
res=add(res,((ll)(a-1)*dp[n-i-1][tr-2])%mod);
//printf("%i\n",res);
tr=max(tr,a+1);
}
res++;
printf("%i\n",res);
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... |