답안 #494185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494185 2021-12-14T16:49:16 Z Khizri 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include "candies.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
vector<int> solve1(vector<int> &c, vector<int> &l,vector<int> &r, vector<int> &v) {
    int n = c.size(),q=l.size();
    vector<int>arr(n);
    for(int ind=0;ind<q;ind++){
        int a=l[ind],b=r[ind],k=v[ind];
        for(int i=a;i<=b;i++){
            arr[i]+=k;
            arr[i]=min(arr[i],c[i]);
            arr[i]=max(arr[i],0);
        }
    }
    return arr;
}
vector<int> solve2(vector<int> &c, vector<int> &l,vector<int> &r, vector<int> &v) {
    int n = c.size(),q=l.size();
    vector<long long>arr(n);
    for(int ind=0;ind<q;ind++){
        int a=l[ind],b=r[ind],k=v[ind];
        arr[a]+=k;
        if(b+1<n){
            arr[b+1]-=k;
        }
    }
    for(int i=1;i<n;i++){
        arr[i]+=arr[i-1];
    }
    for(int i=0;i<n;i++){
        arr[i]=min(arr[i],c[i]);
    }
    return arr;
}
vector<int> distribute_candies(vector<int> c, vector<int> l,vector<int> r, vector<int> v) {
    int n = c.size(),q=l.size();
    if(n<=2000&&q<=2000){
        return solve1(c,l,r,v);
    }
    return solve2(c,l,r,v);
}

Compilation message

candies.cpp: In function 'std::vector<int> solve2(std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
candies.cpp:32:31: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   32 |         arr[i]=min(arr[i],c[i]);
      |                               ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.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:
candies.cpp:32:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   32 |         arr[i]=min(arr[i],c[i]);
      |                               ^
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.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:
candies.cpp:32:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   32 |         arr[i]=min(arr[i],c[i]);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/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:
candies.cpp:32:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |         arr[i]=min(arr[i],c[i]);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:2:
/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:
candies.cpp:32:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   32 |         arr[i]=min(arr[i],c[i]);
      |                               ^
candies.cpp:34:12: error: could not convert 'arr' from 'vector<long long int>' to 'vector<int>'
   34 |     return arr;
      |            ^~~
      |            |
      |            vector<long long int>