# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121929 | vjudge1 | Calvinball championship (CEOI15_teams) | C++17 | 356 ms | 760 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>
#define ll long long
#define pb push_back
#define in insert
#define fi first
#define se second
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 1e4 + 5; /// mind this
const int MAX = 2e6 + 123;
const int BS = 61;
const int mod = 1e6 + 7;
ll dp[2][sz];
ll bp(ll a, ll b){
ll res = 1;
a %= mod;
while(b){
if(b & 1){
res = (res * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return res;
}
void solve(){
ll n, i, j, hi = 0, ans = 1;
cin >> n;
vl v(n + 1), p(n + 1, 0);
dp[0][0] = 1;
for(i = 1; i <= n; i++){
cin >> v[i];
p[i] = max(p[i - 1], v[i]);
dp[0][i] = 1;
}
for(i = 0; i < n; i ++){
// cout << i << ": ";
for(j = 0; i && j <= n - i; j++){
dp[i & 1][j] = (dp[(i & 1) ^ 1][j + 1] + (dp[(i & 1) ^ 1][j] * j) % mod) % mod;
// cout << dp[i][j] << ' ';
}
for (j = 1; j < v[n - i]; j++){
ans = (ans + dp[i & 1][max(j, p[n - i - 1])]) % mod;
}
// cout << endl;
}
cout << ans<< endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while(t--){
solve();
}
}
/*
3
1 2 2
*/
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... |