Submission #1331525

#TimeUsernameProblemLanguageResultExecution timeMemory
1331525kawhietSafety (NOI18_safety)C++20
Compilation error
0 ms0 KiB
a#include <bits/stdc++.h>
using namespace std;

#define int long long

constexpr int inf = 1e18;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, h;
    cin >> n >> h;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int m = ranges::max(a);
    vector<vector<int>> dp(n, vector<int>(m + 1, inf));
    for (int i = 0; i <= m; i++) {
        dp[0][i] = abs(i - a[0]);
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= m; j++) {
            for (int k = 0; k <= m; k++) {
                if (abs(j - k) > h) continue;
                dp[i][j] = min(dp[i][j], dp[i - 1][k] + abs(a[i] - j));
            }
        }
    }
    int ans = ranges::min(dp[n - 1]);
    cout << ans << '\n';
    return 0;
}

Compilation message (stderr)

safety.cpp:1:2: error: stray '#' in program
    1 | a#include <bits/stdc++.h>
      |  ^
safety.cpp:1:1: error: 'a' does not name a type
    1 | a#include <bits/stdc++.h>
      | ^
safety.cpp: In function 'int main()':
safety.cpp:9:5: error: 'ios' has not been declared
    9 |     ios::sync_with_stdio(false);
      |     ^~~
safety.cpp:10:5: error: 'cin' was not declared in this scope
   10 |     cin.tie(nullptr);
      |     ^~~
safety.cpp:13:5: error: 'vector' was not declared in this scope
   13 |     vector<int> a(n);
      |     ^~~~~~
safety.cpp:4:13: error: expected primary-expression before 'long'
    4 | #define int long long
      |             ^~~~
safety.cpp:13:12: note: in expansion of macro 'int'
   13 |     vector<int> a(n);
      |            ^~~
safety.cpp:15:16: error: 'a' was not declared in this scope
   15 |         cin >> a[i];
      |                ^
safety.cpp:17:13: error: 'ranges' has not been declared
   17 |     int m = ranges::max(a);
      |             ^~~~~~
safety.cpp:17:25: error: 'a' was not declared in this scope
   17 |     int m = ranges::max(a);
      |                         ^
safety.cpp:4:13: error: expected primary-expression before 'long'
    4 | #define int long long
      |             ^~~~
safety.cpp:18:19: note: in expansion of macro 'int'
   18 |     vector<vector<int>> dp(n, vector<int>(m + 1, inf));
      |                   ^~~
safety.cpp:20:9: error: 'dp' was not declared in this scope
   20 |         dp[0][i] = abs(i - a[0]);
      |         ^~
safety.cpp:20:20: error: 'abs' was not declared in this scope
   20 |         dp[0][i] = abs(i - a[0]);
      |                    ^~~
safety.cpp:25:21: error: 'abs' was not declared in this scope
   25 |                 if (abs(j - k) > h) continue;
      |                     ^~~
safety.cpp:26:17: error: 'dp' was not declared in this scope
   26 |                 dp[i][j] = min(dp[i][j], dp[i - 1][k] + abs(a[i] - j));
      |                 ^~
safety.cpp:26:57: error: 'abs' was not declared in this scope
   26 |                 dp[i][j] = min(dp[i][j], dp[i - 1][k] + abs(a[i] - j));
      |                                                         ^~~
safety.cpp:26:28: error: 'min' was not declared in this scope; did you mean 'main'?
   26 |                 dp[i][j] = min(dp[i][j], dp[i - 1][k] + abs(a[i] - j));
      |                            ^~~
      |                            main
safety.cpp:30:15: error: 'ranges' has not been declared
   30 |     int ans = ranges::min(dp[n - 1]);
      |               ^~~~~~
safety.cpp:30:27: error: 'dp' was not declared in this scope
   30 |     int ans = ranges::min(dp[n - 1]);
      |                           ^~
safety.cpp:31:5: error: 'cout' was not declared in this scope
   31 |     cout << ans << '\n';
      |     ^~~~