답안 #991923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991923 2024-06-03T12:02:24 Z overwatch9 Safety (NOI18_safety) C++17
4 / 100
2000 ms 262144 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int n, h;
vector <ll> s;
vector <vector <ll>> dp;
ll solve(int i, int prev) {
    if (i > n)
        return 0;
    if (dp[i][prev] != -1)
        return dp[i][prev];
    ll ans = 1e18;
    for (int j = max(0, prev - h); j <= min(prev + h, 800); j++)
        ans = min(ans, solve(i+1, j) + abs(j - s[i]));
    dp[i][prev] = ans;
    return ans;
}
int main()
{
    cin >> n >> h;
    s = vector <ll> (n+1);
    for (int i = 1; i <= n; i++)
        cin >> s[i];
    int maxs = *max_element(s.begin(), s.end());
    dp = vector <vector <ll>> (n+1, vector <ll> (800 + 1, -1));
    ll ans = 1e18;
    for (int i = 0; i <= 800; i++) {
        dp = vector <vector <ll>> (n+1, vector <ll> (800 + 1, -1));
        ans = min(ans, solve(1, i));
    }
    cout << ans << '\n';
}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:26:9: warning: unused variable 'maxs' [-Wunused-variable]
   26 |     int maxs = *max_element(s.begin(), s.end());
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Execution timed out 2051 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 5 ms 428 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 135 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Execution timed out 2051 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Execution timed out 2051 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Execution timed out 2051 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Execution timed out 2051 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Execution timed out 2051 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -