이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, L;
cin >> N >> L;
vector<pair<int, int>> Tab(N);
for (int i = 0; i < N; i++)
cin >> Tab[i].first;
for (int i = 0; i < N; i++)
cin >> Tab[i].second;
sort(Tab.begin(), Tab.end());
vector<vector<vector<vector<int>>>> dp(N, vector<vector<vector<int>>>(N, vector<vector<int>>(N + 1, vector<int>(2, 1234567890))));
int maxx = 0;
dp[0][0][(Tab[0].first <= Tab[0].second) ? 1 : 0][0] = Tab[0].first;
dp[N - 1][N - 1][(L - Tab[N - 1].first <= Tab[N - 1].second) ? 1 : 0][1] = L - Tab[N - 1].first;
for (int i = 0; i < N; i++)
{
for (int left = 0; left < N; left++)
{
int right = (left + N - i) % N;
for (int nb = 0; nb <= N; nb++)
{
if (min(dp[left][right][nb][0], dp[left][right][nb][1]) == 1234567890)
continue;
maxx = max(maxx, nb);
int next = (left + 1) % N, dist = (Tab[left].first < Tab[next].first) ? Tab[next].first - Tab[left].first : Tab[next].first + L - Tab[left].first;
dp[next][right][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][0] = min(dp[left][right][nb][0] + dist, dp[next][right][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][0]);
next = (left + 1) % N, dist = (Tab[right].first < Tab[next].first) ? Tab[next].first - Tab[right].first : Tab[next].first + L - Tab[right].first;
dp[next][right][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][0] = min(dp[left][right][nb][1] + dist, dp[next][right][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][0]);
next = (right - 1 + N) % N, dist = (Tab[right].first > Tab[next].first) ? Tab[right].first - Tab[next].first : Tab[right].first + L - Tab[next].first;
dp[left][next][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][1] = min(dp[left][right][nb][1] + dist, dp[left][next][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][1]);
next = (right - 1 + N) % N, dist = (Tab[left].first > Tab[next].first) ? Tab[left].first - Tab[next].first : Tab[left].first + L - Tab[next].first;
dp[left][next][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][1] = min(dp[left][right][nb][0] + dist, dp[left][next][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][1]);
}
}
}
cout << maxx;
}
# | 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... |