53622023-04-26 14:14:58horvathabelSzigetek (35 pont)cpp17Wrong answer 1/3527ms6804 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }

    vector<int> distances(n);
    distances[0] = 0;
    for (int i = 1; i < n; i++) {
        distances[i] = min(i, n - i);
    }

    vector<int> optimal(n);

    optimal[0] = d[0];
    if (n > 1) {
        optimal[1] = min(d[0] + d[1], d[1]);
    }

    for (int i = 2; i < n; i++) {
        optimal[i] = min(optimal[i-1] + d[i], optimal[i-2] + min(d[i-1], d[i]));
    }

    int result = optimal[n-1];

    if (distances[n-1] == 1) {
        result = min(result, d[n-2]);
    }

    cout << result << endl;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base1/35
1Wrong answer0/03ms1812 KiB
2Wrong answer0/027ms4448 KiB
3Wrong answer0/12ms2268 KiB
4Wrong answer0/13ms2480 KiB
5Wrong answer0/12ms2752 KiB
6Accepted1/12ms2844 KiB
7Wrong answer0/13ms3080 KiB
8Wrong answer0/23ms3128 KiB
9Wrong answer0/23ms3332 KiB
10Wrong answer0/23ms3684 KiB
11Wrong answer0/23ms3652 KiB
12Wrong answer0/24ms3736 KiB
13Wrong answer0/24ms3784 KiB
14Wrong answer0/27ms4032 KiB
15Wrong answer0/29ms4232 KiB
16Wrong answer0/214ms4500 KiB
17Wrong answer0/219ms5212 KiB
18Wrong answer0/221ms5788 KiB
19Wrong answer0/224ms6000 KiB
20Wrong answer0/224ms6352 KiB
21Wrong answer0/227ms6804 KiB
22Wrong answer0/227ms6572 KiB