답안 #83099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83099 2018-11-05T09:14:07 Z chunghan 막대기 (KOI13_game) C++17
100 / 100
107 ms 19324 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long int lld;
typedef pair<int, int> pii;

int N, l;
vector<pii> S;
vector<int> U, L;
lld D[100005], E[100005];

inline int getx(int x) {
    return lower_bound(U.begin(), U.end(), x) - U.begin();
}

inline int gety(int y) {
    return lower_bound(L.begin(), L.end(), y) - L.begin();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> N >> l;
    for(int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        S.push_back(pii(x, y));
        U.push_back(x);
        L.push_back(y);
    }
    sort(S.begin(), S.end());
    sort(U.begin(), U.end());
    sort(L.begin(), L.end());
    U.erase(unique(U.begin(), U.end()), U.end());
    L.erase(unique(L.begin(), L.end()), L.end());
    lld rst = 0;
    for(int i = 0; i < N; i++) {
        int a = getx(S[i].first);
        int b = gety(S[i].second);
        lld ta, tb;
        ta = max(D[a], E[b] + abs(S[i].first-S[i].second) + l);
        tb = max(E[b], D[a] + abs(S[i].first-S[i].second) + l);
        D[a] = ta;
        E[b] = tb;
        //cout << a << ' ' << D[a] << ' ';
        //cout << b <<  ' ' << E[b] << endl;
    }
    for(int i = 0; i < N; i++)
        rst = max(rst, max(D[getx(S[i].first)], E[gety(S[i].second)]));
    cout << rst << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 3 ms 644 KB Output is correct
4 Correct 2 ms 648 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1748 KB Output is correct
2 Correct 47 ms 2176 KB Output is correct
3 Correct 61 ms 4052 KB Output is correct
4 Correct 56 ms 4892 KB Output is correct
5 Correct 60 ms 5748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5748 KB Output is correct
2 Correct 2 ms 5748 KB Output is correct
3 Correct 2 ms 5748 KB Output is correct
4 Correct 2 ms 5748 KB Output is correct
5 Correct 2 ms 5748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5748 KB Output is correct
2 Correct 3 ms 5748 KB Output is correct
3 Correct 3 ms 5748 KB Output is correct
4 Correct 3 ms 5748 KB Output is correct
5 Correct 2 ms 5748 KB Output is correct
6 Correct 3 ms 5748 KB Output is correct
7 Correct 3 ms 5748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5748 KB Output is correct
2 Correct 10 ms 5748 KB Output is correct
3 Correct 33 ms 6524 KB Output is correct
4 Correct 85 ms 9104 KB Output is correct
5 Correct 107 ms 10664 KB Output is correct
6 Correct 80 ms 12628 KB Output is correct
7 Correct 88 ms 14504 KB Output is correct
8 Correct 69 ms 16064 KB Output is correct
9 Correct 12 ms 16064 KB Output is correct
10 Correct 9 ms 16064 KB Output is correct
11 Correct 76 ms 17964 KB Output is correct
12 Correct 73 ms 19324 KB Output is correct