답안 #637876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637876 2022-09-03T13:35:01 Z BlancaHM Rabbit Carrot (LMIO19_triusis) C++14
63 / 100
113 ms 10480 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void updateTree(int x, int L, int R, int ind, int newVal, vector<int> & seg) {
    if (ind < L || ind > R) {
        return;
    } else if (L == R) {
        seg[x] = newVal;
    } else {
        int mid = L + (R-L)/2;
        updateTree(2*x, L, mid, ind, newVal, seg);
        updateTree(2*x+1, mid+1, R, ind, newVal, seg);
        seg[x] = max(seg[2*x], seg[2*x+1]);
    }
}

int queryTree(int x, int L, int R, int startInd, int endInd, vector<int> & seg) {
    if (startInd > R || endInd < L) {
        return 0;
    } else if (startInd <= L && endInd >= R) {
        return seg[x];
    } else {
        int mid = L + (R-L)/2;
        int leftAns = queryTree(2*x, L, mid, startInd, endInd, seg);
        int rightAns = queryTree(2*x+1, mid+1, R, startInd, endInd, seg);
        return max(leftAns, rightAns);
    }
}

int lnds(vector<long long int> & L) {
    // returns the length of the longest non-decreasing subsequence of L
    int N = (int) L.size();
    if (N == 0)
        return 0;
    vector<pair<long long int, int>> indL(N);
    for (int i = 0; i < N; i++) {
        indL[i] = make_pair(L[i], i);
    }
    sort(indL.begin(), indL.end());
    vector<int> DP(N, 0);
    vector<int> seg(4*N, 0);
    updateTree(1, 0, N-1, 0, 1, seg);
    for (int i = 1; i < N; i++) {
        int curPos = indL[i].second;
        int bestPrev = queryTree(1, 0, N-1, 0, curPos-1, seg);
        updateTree(1, 0, N-1, curPos, bestPrev+1, seg);
    }
    return queryTree(1, 0, N-1, 0, N-1, seg);
}

int minChanges(vector<long long int> & heights, long long int M) {
    int N = (int) heights.size();
    vector<long long int> altered;
    for (int i = 0; i < N; i++) {
        long long int newH = M*((long long int) i+1) - heights[i];
        if (newH >= 0) {
            altered.push_back(newH);
        }
    }
    return N - lnds(altered);
}

int main() {
    int N;
    long long int M;
    cin >> N >> M;
    vector<long long int> heights(N);
    for (int i = 0; i < N; i++) {
        cin >> heights[i];
    }
    cout << minChanges(heights, M) << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 2 ms 472 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 292 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 212 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 3 ms 596 KB Output is correct
38 Correct 3 ms 468 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 4 ms 596 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 4 ms 468 KB Output is correct
43 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 472 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 3 ms 468 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 3 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 292 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 90 ms 10480 KB Output is correct
45 Correct 71 ms 1856 KB Output is correct
46 Correct 113 ms 6112 KB Output is correct
47 Incorrect 111 ms 6072 KB Output isn't correct
48 Halted 0 ms 0 KB -