Submission #544649

# Submission time Handle Problem Language Result Execution time Memory
544649 2022-04-02T14:12:45 Z pokmui9909 막대기 (KOI13_game) C++17
100 / 100
60 ms 7028 KB
#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
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2504 KB Output is correct
2 Correct 21 ms 2556 KB Output is correct
3 Correct 40 ms 4552 KB Output is correct
4 Correct 38 ms 4456 KB Output is correct
5 Correct 40 ms 4464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 980 KB Output is correct
2 Correct 6 ms 980 KB Output is correct
3 Correct 21 ms 3468 KB Output is correct
4 Correct 60 ms 5748 KB Output is correct
5 Correct 57 ms 5864 KB Output is correct
6 Correct 51 ms 6604 KB Output is correct
7 Correct 55 ms 6120 KB Output is correct
8 Correct 42 ms 7028 KB Output is correct
9 Correct 6 ms 980 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 49 ms 5684 KB Output is correct
12 Correct 52 ms 5796 KB Output is correct