제출 #1095555

#제출 시각아이디문제언어결과실행 시간메모리
1095555Aviansh선물상자 (IOI15_boxes)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#include "boxes.h"

using namespace std;

long long delivery(int n, int k, int l, int b[]) {
    int split = l/2;
    int lrem = 0;
    int lasleft = *(upper_bound(b,b+n,l/2)-1);
    int lasright = l-*upper_bound(b,b+n,l/2);
    priority_queue<int, vector<int>, greater<int>>pq;
    map<int,int>mp;
    for(int i = 0;i<n;i++){
        mp[b[i]]++;
    }
    for(pair<int,int>p:mp){
        if(p.first>split){
            break;
        }
        for(int i = 0;i<p.second/k;i++){
            pq.push(p.first);
            //cout << "pushing1: " << p.first << "\n";
        }
        lrem+=p.second%k;
        if(lrem>=k){
            pq.push(p.first);
            //cout << "pushing2: " << p.first << "\n";
            lrem%=k;
        }
    }
    int rrem = 0;
    for(map<int,int>::iterator it = (--mp.end());it!=mp.begin();it--){
        pair<int,int>p = *it;
        if(p.first<=split){
            break;
        }
        for(int i = 0;i<p.second/k;i++){
            pq.push(l-p.first);
            //cout << "pushing3: " << l-p.first << "\n";
        }
        rrem+=p.second%k;
        if(lrem>=k){
            pq.push(l-p.first);
            //cout << "pushing4: " << l-p.first << "\n";
            rrem%=k;
        }
    }
    long long ans = 0;
    while(!pq.empty()){
        int tp = pq.top();
        //cout << "popped: " << tp << "\n";
        pq.pop();
        ans+=tp*2;
    }
    //cout << "ans rn: " << ans << "\n";
    if(lrem||rrem){
        if(lrem==0){
            ans+=2*lasright;
        }
        else if(rrem == 0){
            ans+=2*lasleft;
        }
        else if(lrem+rrem<=k){
            ans+=l;
        }
        else{
            ans+=min(lasleft+lasright,1LL*2*lasleft+1LL*2*lasright);
        }
    }
    //cout << "ans after add: " << ans << "\n";
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:67:67: error: no matching function for call to 'min(int, long long int)'
   67 |             ans+=min(lasleft+lasright,1LL*2*lasleft+1LL*2*lasright);
      |                                                                   ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
boxes.cpp:67:67: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   67 |             ans+=min(lasleft+lasright,1LL*2*lasleft+1LL*2*lasright);
      |                                                                   ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
boxes.cpp:67:67: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   67 |             ans+=min(lasleft+lasright,1LL*2*lasleft+1LL*2*lasright);
      |                                                                   ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
boxes.cpp:67:67: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   67 |             ans+=min(lasleft+lasright,1LL*2*lasleft+1LL*2*lasright);
      |                                                                   ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from boxes.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
boxes.cpp:67:67: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   67 |             ans+=min(lasleft+lasright,1LL*2*lasleft+1LL*2*lasright);
      |                                                                   ^