// 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
teams.cpp:27:45: warning: overflow in implicit constant conversion [-Woverflow]
const ll maxn=1e4+10, lg=20, mod=1e9+7, inf=1e18;
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
366 ms |
512 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
93 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
358 ms |
736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |