답안 #141513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141513 2019-08-08T09:37:10 Z meatrow Safety (NOI18_safety) C++17
0 / 100
3 ms 504 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 1e3 + 5;

int s[N];
ll dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, h;
    cin >> n >> h;
    vector<int> a;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        a.push_back(max(s[i] - h, 0));
        a.push_back(s[i]);
        a.push_back(s[i] + h);
    }
    sort(a.begin(), a.end());
    a.resize(a.end() - unique(a.begin(), a.end()));
    int m = a.size();
    for (int j = 0; j < m; j++) {
        dp[0][j] = abs(s[0] - j);
    }
    for (int i = 1; i < n; i++) {
        int l = 0, r = 0;
        multiset<ll> q;
        for (int j = 0; j < m; j++) {
            while (r < m && a[r] <= j + h) {
                q.insert(dp[i - 1][r]);
                r++;
            }
            while (l < m && a[l] < j - h) {
                q.erase(q.find(dp[i - 1][l]));
                l++;
            }
            dp[i][j] = abs(s[i] - a[j]) + *q.begin();
        }
    }
    ll ans = LLONG_MAX;
    for (int i = 0; i < m; i++) {
        ans = min(ans, dp[n - 1][i]);
    }
    cout << ans;
    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Halted 0 ms 0 KB -