CSES - Datatähti 2020 alku - Results
Submission details
Task:Mastot
Sender:Epe
Submission time:2019-10-08 17:50:20 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:79:56: error: no matching function for call to 'min(int&, long long int)'
                 for(int l = p+1; l <= min(end,p+kantama); l++){
                                                        ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from input/code.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
input/code.cpp:79:56:...

Code

#include <bits/stdc++.h>

using namespace std;

vector<int> kantamat;
vector<long long> hinnat;

//index ja edullisin
vector<pair<int, long long>> osiot(10000);
int amount;

//n = 0, 1, 2, 3..
//k = 2, 2, 3, 1, 2, 4..
//h = 0, 4, 1, 3..

int base = 4;

int bid(int i){
    return (i-(i%base))/base;
}

int cbs(int i){
    return bid(i)*base;
}

int cbe(int i){
    return cbs(i) + base -1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> amount;

    vector<long long> edullisin(amount);

    for (int i = 0; i < amount; i++) {
        int temp;
        cin >> temp;
        kantamat.push_back(temp);
    }

    //Lähetin ei maksa mitään
    hinnat.push_back(0);

    //cout << "> ";

    for (int i = 0; i < amount - 1; i++) {
        long long temp = 2;
        cin >> temp;
        hinnat.push_back(temp);
    }

    //viimeinen osio
    int last = bid(amount-1);


    for(int i = last; i >= 0; i--){
        int start = base*i;
        int end = min(base*i+base-1,amount-1);

        long long osion_edullisin_hinta = LLONG_MAX;
        int osion_edullisimman_index = INT_MAX;

        //käydään läpi osio
        for(int p = end; p >= start; p--){
            long long kantama = kantamat[p];

            //Etsitään lähettimelle kannattavin seuraava linkki
            long long edullisin_loydetty_hinta = LLONG_MAX;
            int edullisimman_index = INT_MAX;


            if(kantama+p >= amount){
                edullisin[p] = hinnat[p];
            } else {

                //Käydään oman osion lähettimet läpi ensin
                for(int l = p+1; l <= min(end,p+kantama); l++){
                    if(edullisin[l] < edullisin_loydetty_hinta){
                        edullisimman_index = l;
                        edullisin_loydetty_hinta = edullisin[l];
                    }
                }

                if(bid(p) != bid(p+kantama)) {
                    //Käydään seuraavat osiot läpi (paitsi viimeinen)
                    for (int l = i + 1; l < bid(p + kantama); l++) {
                        if (osiot[l].second < edullisin_loydetty_hinta) {
                            edullisin_loydetty_hinta = osiot[l].second;
                            edullisimman_index = osiot[l].first;
                        }
                    }

                    //Käydään viimeinen osio läpi
                    for (int l = cbs(p + kantama); l <= p + kantama; l++) {
                        if (edullisin[l] < edullisin_loydetty_hinta) {
                            edullisimman_index = l;
                            edullisin_loydetty_hinta = edullisin[l];
                        }
                    }
                }
                edullisin[p] = edullisin_loydetty_hinta + hinnat[p];
            }




            if(edullisin[p] < osion_edullisin_hinta){
                osion_edullisin_hinta = edullisin[p];
                osion_edullisimman_index = p;
            }
        }

        osiot[i] = make_pair(osion_edullisimman_index, osion_edullisin_hinta);



    }

    cout << edullisin[0] << endl;
}