Submission #851078

# Submission time Handle Problem Language Result Execution time Memory
851078 2023-09-18T13:25:14 Z overwatch9 Rabbit Carrot (LMIO19_triusis) C++17
14 / 100
1000 ms 956 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxa = 5000 * 2 + 1;
struct stree {
    #define lc v*2
    #define rc v*2+1
    vector <int> tree;
    stree (int sz) {

        tree.resize(sz * 4, 1e9);
    }
    void pushup(int v) {
        tree[v] = min(tree[lc], tree[rc]);
    }
    void update(int v, int tl, int tr, int p, int val) {
        if (tl > p || tr < p)
            return;
        if (tl == tr) {
            tree[v] = val;
            return;
        }
        int tm = (tl + tr) / 2;
        update(lc, tl, tm, p, val);
        update(rc, tm+1, tr, p, val);
        pushup(v);
    }
    int query(int v, int tl, int tr, int l, int r) {
        if (tl > r || tr < l)
            return 1e9;
        if (tl >= l && tr <= r)
            return tree[v];
        int tm = (tl + tr) / 2;
        int a = query(lc, tl, tm, l, r);
        int b = query(rc, tm+1, tr, l, r);
        return min(a, b);
    }
};
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 <stree> trees(2, stree (maxa));
    vector <vector <int>> dp(2, vector <int> (maxa));
    for (int i = 0; i < maxa; i++) {
        if (i <= m && i == nums[1]) {
            dp[1][i] = 0;
            trees[1].update(1, 0, maxa, nums[1], 0);
        } else if (i <= m) {
            trees[1].update(1, 0, maxa, i, 1);
            dp[1][i] = 1;
        } else {
            dp[1][i] = 1e9;
            trees[1].update(1, 0, maxa, i, 1e9);
        }
    }
    swap(prev, curr);
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < maxa; j++) {
            int a = trees[prev].query(1, 0, maxa, max(0, j-m), maxa);
            dp[curr][j] = a;
            if (nums[i] != j) {
                dp[curr][j]++;
            }
        }
        for (int j = 0; j < maxa; j++) {
            trees[curr].update(1, 0, maxa, j, dp[curr][j]);
        }
        swap(prev, curr);
    }
    int ans = 1e9;
    for (int i = 0; i < maxa; i++)
        ans = min(ans, dp[prev][i]);
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 12 ms 856 KB Output is correct
5 Correct 15 ms 860 KB Output is correct
6 Correct 17 ms 856 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 17 ms 856 KB Output is correct
9 Correct 14 ms 856 KB Output is correct
10 Correct 13 ms 856 KB Output is correct
11 Correct 12 ms 856 KB Output is correct
12 Correct 14 ms 856 KB Output is correct
13 Correct 12 ms 856 KB Output is correct
14 Correct 15 ms 956 KB Output is correct
15 Correct 12 ms 856 KB Output is correct
16 Correct 12 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 12 ms 856 KB Output is correct
5 Correct 15 ms 860 KB Output is correct
6 Correct 17 ms 856 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 17 ms 856 KB Output is correct
9 Correct 14 ms 856 KB Output is correct
10 Correct 13 ms 856 KB Output is correct
11 Correct 12 ms 856 KB Output is correct
12 Correct 14 ms 856 KB Output is correct
13 Correct 12 ms 856 KB Output is correct
14 Correct 15 ms 956 KB Output is correct
15 Correct 12 ms 856 KB Output is correct
16 Correct 12 ms 860 KB Output is correct
17 Correct 6 ms 856 KB Output is correct
18 Correct 5 ms 856 KB Output is correct
19 Correct 3 ms 856 KB Output is correct
20 Execution timed out 1018 ms 856 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 856 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 3 ms 856 KB Output is correct
4 Execution timed out 1018 ms 856 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 856 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 3 ms 856 KB Output is correct
4 Execution timed out 1018 ms 856 KB Time limit exceeded
5 Halted 0 ms 0 KB -