This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Do you knOW what it feels like?
// To be TorTured by your own MinD?
// I don't wanna feel the PAIN.
// I BeG you to KILL me, pleASE...
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os")
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
typedef int ll;
typedef pair<ll,ll> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=1e4+10, lg=20, mod=1e9+7, inf=1e18;
ll n;
long long dp[2][maxn],ans=1;
pll ad[maxn];
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;
ll mx=0;
for(int i=1;i<=n;i++){
ll x; cin>>x;
ad[n-i]={mx,x-1};
//cout<<n-i<<' '<<mx<<' '<<x-1<<endl;
mx=max(mx,x);
}
ans+=ad[0].S, ans%=mod;
for(int j=0;j<=n;j++) dp[0][j]=1;
for(int ii=1,i,gi;ii<=n;ii++){ i=ii%2; gi=1-i;
dp[i][0]=0;
for(int j=1;j<=n;j++) dp[i][j]=((dp[gi][j]*j%mod)+dp[gi][j-1])%mod;
ans+=dp[i][ad[ii].F]*ad[ii].S%mod, ans%=mod;
}
cout<<ans;
return 0;
}
Compilation message (stderr)
teams.cpp:27:45: warning: overflow in implicit constant conversion [-Woverflow]
const ll maxn=1e4+10, lg=20, mod=1e9+7, inf=1e18;
^~~~
# | 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... |