이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll bad = -1e17;
map <ll, ll> dp[202];
ll n, arr[202], l;
ll ans (ll pos, ll cur) {
if (pos == -n - 1) return (cur == l ? 0ll : bad);
if (dp[pos + n].count(cur)) return dp[pos + n][cur];
if (pos == -n - 1) {
return dp[pos + n][cur] = (cur == l ? 0ll : bad);
}
ll ret = ans(pos - 1, cur);
for (int i = 1; i <= arr[pos + n]; i++) {
ret = max(ret, i + ans(pos - 1, cur + pos * i));
}
return dp[pos + n][cur] = ret;
}
int main () {
cin >> n >> l;
for (int i = -n; i <= n; i++) cin >> arr[i + n];
ll z = ans(n, 0);
if (z < 0) {
cout << "impossible\n";
} else {
cout << z << '\n';
}
}
# | 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... |