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 int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
int n;
vector<int> v;
ll dp[1005][2];
ll f(int pos, int under) {
if(pos == n + 1) return under;
if(dp[pos][under] != -1) return dp[pos][under];
ll ans = 0;
for(int i=1; i<=pos; i++) {
if(!under && i > v[pos]) continue;
ans = (ans + f(pos+1, under|(i < v[pos])));
}
return dp[pos][under] = ans;
}
signed main() {
memset(dp, -1, sizeof(dp));
cin >> n;
v.resize(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
cout << f(1, 0) << '\n';
return 0;
}
# | 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... |