이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
pair<ll, ll> A[100005];
ll D[1000005][2];
vector<ll> X, Y;
ll N, L;
int main()
{
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> N >> L;
for(int i = 1; i <= N; i++)
{
cin >> A[i].first >> A[i].second;
X.push_back(A[i].first);
Y.push_back(A[i].second);
}
X.push_back(N); Y.push_back(N);
sort(A + 1, A + N + 1);
sort(X.begin(), X.end());
sort(Y.begin(), Y.end());
X.erase(unique(X.begin(), X.end()), X.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
ll ans = 0;
for(int i = 1; i <= N; i ++)
{
ll x = lower_bound(X.begin(), X.end(), A[i].first) - X.begin();
ll y = lower_bound(Y.begin(), Y.end(), A[i].second) - Y.begin();
ll k = abs(X[x] - Y[y]) + L;
ll a = D[x][0], b = D[y][1];
D[x][0] = max(D[x][0], b + k);
D[y][1] = max(D[y][1], a + k);
ans = max({ans, D[x][0], D[y][1]});
}
cout << ans;
}
# | 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... |