Submission #83087

# Submission time Handle Problem Language Result Execution time Memory
83087 2018-11-05T07:44:38 Z chunghan 막대기 (KOI13_game) C++17
0 / 100
55 ms 11656 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long int lld;

int N, L, A[100000], B[100000];

vector<int> X[100000], Y[100000];

lld D[100000], dist[100000];

lld solve(int i) {
    if(D[i] != -1) return D[i];
    int x = A[i], y = B[i];
    lld ret = 0;
    for(auto p : X[x]) 
        if(p < i && B[p] < B[i])
            ret = max(ret, solve(p));
    for(auto p : Y[y])
        if(p < i && A[p] < A[i])
            ret = max(ret, solve(p));
    //cout << i << ' ' << ret+dist[i] << endl;
    return D[i] = ret + dist[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    memset(D, -1, sizeof(D));
    cin >> N >> L;
    for(int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        A[i] = x; B[i] = y;
        X[x].push_back(i); Y[y].push_back(i);
        dist[i] = abs(y-x) + L;
        //cout << i << ' ' << dist[i] << endl;
    }
    lld rst = 0;
    for(int i = 0; i < N; i++) rst = max(rst, solve(i));
    cout << rst;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5880 KB Output is correct
2 Incorrect 7 ms 5984 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 7332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 7332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 7332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 11656 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -