답안 #977052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977052 2024-05-07T10:50:10 Z phoenix Safety (NOI18_safety) C++17
0 / 100
2000 ms 3324 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 200'200;

int n, h;

ll s[N];


void solve() {
    cin >> n >> h;
    for (int i = 1; i <= n; i++)
        cin >> s[i];
    
    set<int> t1, t2;
    t1.insert(s[1]);
    t2.insert(s[1]);
    ll base = 0;

    for (int i = 2; i <= n; i++) {
        set<int> st;
        {
            for (int c : t1) st.insert(c - h);
            t1 = st;
            st.clear();
        }
        {
            for (int c : t2) st.insert(c + h);
            t2 = st;
            st.clear();
        }
        int l = *(--t1.end()), r = *t2.begin();
        if (l <= s[i] && s[i] <= r) {
            t1.insert(s[i]);
            t2.insert(s[i]);
        } else
        if (s[i] < l) {
            t1.insert(s[i]);
            t1.erase(l);
            t2.insert(l);
            base += l - *(--t1.end());
        } else 
        if (r < s[i]) {
            t2.insert(s[i]);
            t2.erase(r);
            t1.insert(r);
            base += *t2.begin() - r;
        }
    }
    cout << base;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int test_cases = 1;
    // cin >> test_cases;
    while (test_cases-->0) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2048 ms 3324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -