Submission #717743

# Submission time Handle Problem Language Result Execution time Memory
717743 2023-04-02T11:59:16 Z AnjaJ Garage (IOI09_garage) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

struct Car
{
    int Num;
    int Weight;
    int OccupiedSpace;

};

struct ParkSpace
{
    int Num;
    int Occupied;
    int Rate;
    bool operator <(ParkSpace c2){
        this->Occupied < c2.Occupied;
    }
};

int main()
{
    int NumCars, NumParking;
    cin>>NumParking>>NumCars;
    vector<Car> cars;
    vector<ParkSpace> Spaces;
    vector<int> Occupied;

    for(int i=1; i<=NumParking; i++)
    {
        ParkSpace P = {i, 0, 0};
        cin>>P.Rate;
        Spaces.push_back(P);
    }
    for(int i=1; i<=NumCars; i++)
    {
        Car C = {i, 0, 0};
        cin>>C.Weight;
        cars.push_back(C);
    }

    int OnEntry;
    queue<Car> Queue;

    int Profit = 0;
    for(int i=1; i<=NumCars*2; i++)
    {
        cin>>OnEntry;
        if(OnEntry < 0)
        {
            cars[OnEntry*-1].OccupiedSpace = 0;
            continue;
        }

        auto p = lower_bound(Spaces.begin(), Spaces.end(), 0);
        if(p == Spaces.end())
        {
            Queue.push(cars[OnEntry]);
        }
        else
        {
            if(Queue.size() == 0)
            {
                (*p).Occupied = 1;
                cars[OnEntry].OccupiedSpace = (*p).Num;
                Profit += cars[OnEntry].OccupiedSpace * (*p).Rate;
            }
            else
            {
                cars[Queue.front().Num].OccupiedSpace = (*p).Num;
                Profit += cars[Queue.front().Num].OccupiedSpace * (*p).Rate;
                Queue.pop();
                i = i-1;
            }
        }
    }
    cout<<Profit;
    return 0;
}

Compilation message

garage.cpp: In member function 'bool ParkSpace::operator<(ParkSpace)':
garage.cpp:21:24: warning: statement has no effect [-Wunused-value]
   21 |         this->Occupied < c2.Occupied;
      |         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~
garage.cpp:22:5: warning: no return statement in function returning non-void [-Wreturn-type]
   22 |     }
      |     ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from garage.cpp:1:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = __gnu_cxx::__normal_iterator<ParkSpace*, std::vector<ParkSpace> >; _Value = const int]':
/usr/include/c++/10/bits/stl_algobase.h:1324:14:   required from '_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<ParkSpace*, std::vector<ParkSpace> >; _Tp = int; _Compare = __gnu_cxx::__ops::_Iter_less_val]'
/usr/include/c++/10/bits/stl_algobase.h:1359:32:   required from '_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = __gnu_cxx::__normal_iterator<ParkSpace*, std::vector<ParkSpace> >; _Tp = int]'
garage.cpp:59:61:   required from here
/usr/include/c++/10/bits/predefined_ops.h:67:22: error: no match for 'operator<' (operand types are 'ParkSpace' and 'const int')
   67 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
garage.cpp:20:10: note: candidate: 'bool ParkSpace::operator<(ParkSpace)'
   20 |     bool operator <(ParkSpace c2){
      |          ^~~~~~~~
garage.cpp:20:31: note:   no known conversion for argument 1 from 'const int' to 'ParkSpace'
   20 |     bool operator <(ParkSpace c2){
      |                     ~~~~~~~~~~^~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from garage.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1096:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)'
 1096 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1096:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from garage.cpp:1:
/usr/include/c++/10/bits/predefined_ops.h:67:22: note:   'ParkSpace' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
   67 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from garage.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1104:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)'
 1104 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1104:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from garage.cpp:1:
/usr/include/c++/10/bits/predefined_ops.h:67:22: note:   'ParkSpace' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   67 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~