답안 #851088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851088 2023-09-18T13:42:25 Z overwatch9 Rabbit Carrot (LMIO19_triusis) C++17
35 / 100
106 ms 600 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxa = 5000 + 1;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector <int> nums(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> nums[i];
    }
    if (m == 0) {
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (nums[i] != 0)
                ans++;
        }
        cout << ans << '\n';
        return 0;
    }
    int prev = 0, curr = 1;
    vector <vector <int>> dp(2, vector <int> (maxa));
    vector <vector <int>> mn_vals(2, vector <int> (maxa));
    bool flag = false;
    for (int i = maxa-1; i >= 0; i--) {
        if (flag || (i <= m && i == nums[1])) {
            dp[1][i] = 0;
            mn_vals[1][i] = 0;
            flag = true;
        } else if (i <= m) {
            mn_vals[1][i] = 1;
            dp[1][i] = 1;
        } else {
            mn_vals[1][i] = 1e9;
            dp[1][i] = 1e9;
        }
    }
    swap(prev, curr);
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < maxa; j++) {
            int a = mn_vals[prev][max(0, j - m)];
            dp[curr][j] = a;
            if (nums[i] != j) {
                dp[curr][j]++;
            }
        }
        for (int j = maxa-1; j >= 0; j--) {
            mn_vals[curr][j] = dp[curr][j];
            if (j+1 < maxa)
                mn_vals[curr][j] = min(mn_vals[curr][j+1], mn_vals[curr][j]);
        }
        swap(prev, curr);
    }
    int ans = 1e9;
    for (int i = 0; i < maxa; i++)
        ans = min(ans, dp[prev][i]);
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 85 ms 544 KB Output is correct
21 Correct 101 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 101 ms 348 KB Output is correct
24 Correct 101 ms 344 KB Output is correct
25 Correct 104 ms 344 KB Output is correct
26 Correct 102 ms 344 KB Output is correct
27 Correct 104 ms 600 KB Output is correct
28 Correct 102 ms 600 KB Output is correct
29 Correct 102 ms 344 KB Output is correct
30 Correct 102 ms 344 KB Output is correct
31 Correct 101 ms 344 KB Output is correct
32 Correct 102 ms 344 KB Output is correct
33 Correct 106 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 85 ms 544 KB Output is correct
5 Correct 101 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 101 ms 348 KB Output is correct
8 Correct 101 ms 344 KB Output is correct
9 Correct 104 ms 344 KB Output is correct
10 Correct 102 ms 344 KB Output is correct
11 Correct 104 ms 600 KB Output is correct
12 Correct 102 ms 600 KB Output is correct
13 Correct 102 ms 344 KB Output is correct
14 Correct 102 ms 344 KB Output is correct
15 Correct 101 ms 344 KB Output is correct
16 Correct 102 ms 344 KB Output is correct
17 Correct 106 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 500 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Incorrect 101 ms 600 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 101 ms 600 KB Output isn't correct
3 Halted 0 ms 0 KB -