이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef vector<vvv> vvvv;
typedef pair<ll, ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define setmax(a, b) a = max(a, b)
const ll INF = 1e18;
const ll mod = 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll N;
cin >> N;
v a(N);
for (ll i = 0; i < N; i++) cin >> a[i];
v firstParkLeft(N, -1), firstParkRight(N, N);
ll lastPark = -1;
for (ll i = 0; i < N; i++)
{
if (a[i] == -1) lastPark = i;
firstParkLeft[i] = lastPark;
}
lastPark = N;
for (ll i = N - 1; i >= 0; i--)
{
if (a[i] == -1) lastPark = i;
firstParkRight[i] = lastPark;
}
vvvv dp(2 * N + 1, vvv(N, vv(N + 1, v(2, 0))));
for (ll firstPos = 2 * N - 1; firstPos >= 0; firstPos--)
{
for (ll secondPos = 0; secondPos < N; secondPos++)
{
for (ll lastEaten = N - 1; lastEaten >= 0; lastEaten--)
{
//state = 0, looking for somewhere to eat
dp[firstPos][secondPos][lastEaten][0] = dp[firstPos][secondPos][lastEaten + 1][0];
if (a[lastEaten] >= 1)
{
ll distance = abs(secondPos - lastEaten);
if ((firstPos + distance) / 2 <= lastEaten)
{
setmax(dp[firstPos][secondPos][lastEaten][0], dp[firstPos + distance][lastEaten][lastEaten + 1][1] + 1);
}
}
if (firstParkLeft[secondPos] > -1)
{
ll distance = abs(secondPos - firstParkLeft[secondPos]);
if (firstPos + distance < 2 * N)
setmax(dp[firstPos][secondPos][lastEaten][1], dp[firstPos + distance][firstParkLeft[secondPos]][lastEaten][0]);
}
if (firstParkRight[secondPos] < N)
{
ll distance = abs(secondPos - firstParkRight[secondPos]);
if (firstPos + distance < 2 * N)
setmax(dp[firstPos][secondPos][lastEaten][1], dp[firstPos + distance][firstParkRight[secondPos]][lastEaten][0]);
}
}
}
}
ll sum = 0;
for (auto x : a) if (x > 0) sum += x;
cout << sum - dp[0][0][0][0] << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tortoise.cpp:29:16: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
29 | const ll 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... |