94852024-02-22 11:15:23AGergoSzigetek (35 pont)cpp17Time limit exceeded 9/35300ms8040 KiB
#include <bits/stdc++.h>

using namespace std;

int n;
vector<int> price;
vector<int> lowestPrice; // lowest price to get to any island

void bejar(int s,int cost)
{
    if(s == n-1)
    {
        if(lowestPrice[s+1] > cost+ price[s+1])
        {
            lowestPrice[s+1] = cost+ price[s+1];
            bejar(s+1,lowestPrice[s+1]);
        }
    }
    else if(s != n)
    {
        if(lowestPrice[s+1] > cost+ price[s+1])
        {
            lowestPrice[s+1] = cost+ price[s+1];
            bejar(s+1,lowestPrice[s+1]);
        }
        if(lowestPrice[s+2] > cost+ price[s+2])
        {
            lowestPrice[s+2] = cost+ price[s+2];
            bejar(s+2,lowestPrice[s+2]);
        }
    }

}
int main()
{
    cin.tie(0);ios::sync_with_stdio(0);
    cin >> n;
    price.resize(n+1);
    lowestPrice.resize(n+1,INT_MAX);

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

    bejar(1,price[1]);
    cout << lowestPrice[n];
}
SubtaskSumTestVerdictTimeMemory
base9/35
1Accepted0/03ms1888 KiB
2Time limit exceeded0/0300ms6844 KiB
3Accepted1/13ms2352 KiB
4Accepted1/13ms2376 KiB
5Accepted1/13ms2608 KiB
6Accepted1/13ms2820 KiB
7Accepted1/13ms2868 KiB
8Accepted2/28ms2920 KiB
9Accepted2/2186ms3112 KiB
10Time limit exceeded0/2250ms3140 KiB
11Time limit exceeded0/2256ms3192 KiB
12Time limit exceeded0/2300ms2320 KiB
13Time limit exceeded0/2256ms2576 KiB
14Time limit exceeded0/2264ms3260 KiB
15Time limit exceeded0/2252ms4044 KiB
16Time limit exceeded0/2268ms4952 KiB
17Time limit exceeded0/2261ms6160 KiB
18Time limit exceeded0/2252ms6640 KiB
19Time limit exceeded0/2268ms7072 KiB
20Time limit exceeded0/2264ms7188 KiB
21Time limit exceeded0/2264ms7956 KiB
22Time limit exceeded0/2261ms8040 KiB