답안 #921179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921179 2024-02-03T12:00:32 Z sleepntsheep Safety (NOI18_safety) C++17
0 / 100
28 ms 5840 KB
#include <iostream>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>

using u32 = unsigned;
using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

using namespace std;
using pt = complex<f80>;
#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 200005

int n;
i64 s[N], m, c, h;

int main()
{
    ShinLena;
    cin >> n >> h;
    priority_queue<i64> l;
    priority_queue<i64, vector<i64>, greater<i64>> r;
    i64 ll{}, lr{}, ymin{}, c{};

    cin >> s[1];
    l.push(s[1]);
    r.push(s[1]);
    ll += h;
    lr += h;

    for (int i = 2; i <= n; ++i)
    {
        cin >> s[i];

        if (s[i] >= r.top() + lr)
        {
            int nl = r.top() + lr;
            r.pop();
            r.push(s[i] - lr);
            r.push(s[i] - lr);
            ymin = r.top() + lr;
            c += ymin - nl;
            l.push(nl + ll);
        }
        else if (s[i] >= l.top() - ll)
        {
            r.push(s[i] - lr);
            l.push(s[i] + ll);
            ymin = s[i];
        }
        else
        {
            int nr = l.top() - ll;
            l.pop();
            l.push(s[i] + ll);
            l.push(s[i] + ll);
            ymin = nr;
            c += nr - (l.top() - ll);
            r.push(nr - lr);
        }

        ll += h;
        lr += h;
    }
    cout << c;

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 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 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 5840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -