답안 #831840

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831840 2023-08-20T15:56:17 Z Essa2006 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "candies.h"
using namespace std;
#define ll long long 
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n=c.size(), q=l.size();
    vector<ll>p(n);
    bool all_pos=1;
    for(int j=0;j<q;j++){
        if(v[j]<0)
            all_pos=0;
    }
    if((ll)n*q<=1e8){
        for(int i=0;i<n;i++){
            for(int j=0;j<q;j++){
                if(i>=l[j] && i<=r[j]){
                    p[i]=min(c[i], max(0, p[i]+v[j]));
                }
            }
        }
        return p;
    }
    if(all_pos){
        for(int j=0;j<q;j++){
            p[l[j]]+=v[j];
            if(r[j]!=n-1)
                p[r[j]+1]-=v[j];
        }
        for(int i=1;i<n;i++){
            p[i]+=p[i-1];
        }
        return p;
    }
    
}

//int main() {
//    int n;
//    assert(1 == scanf("%d", &n));
//    std::vector<int> c(n);
//    for(int i = 0; i < n; ++i) {
//        assert(scanf("%d", &c[i]) == 1);
//    }
//
//    int q;
//    assert(1 == scanf("%d", &q));
//    std::vector<int> l(q), r(q), v(q);
//    for(int i = 0; i < q; ++i) {
//        assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
//    }
//
//    std::vector<int> ans = distribute_candies(c, l, r, v);
//
//    for(int i = 0; i < n; ++i) {
//        if (i > 0) {
//            printf(" ");
//        }
//        printf("%d", ans[i]);
//    }
//    printf("\n");
//    fclose(stdout);
//    return 0;
//}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:22:52: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   22 |                     p[i]=min(c[i], max(0, p[i]+v[j]));
      |                                                    ^
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 candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
candies.cpp:22:52: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   22 |                     p[i]=min(c[i], max(0, p[i]+v[j]));
      |                                                    ^
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 candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
candies.cpp:22:52: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   22 |                     p[i]=min(c[i], max(0, p[i]+v[j]));
      |                                                    ^
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:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
candies.cpp:22:52: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   22 |                     p[i]=min(c[i], max(0, p[i]+v[j]));
      |                                                    ^
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:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
candies.cpp:22:52: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   22 |                     p[i]=min(c[i], max(0, p[i]+v[j]));
      |                                                    ^
candies.cpp:26:16: error: could not convert 'p' from 'vector<long long int>' to 'vector<int>'
   26 |         return p;
      |                ^
      |                |
      |                vector<long long int>
candies.cpp:37:16: error: could not convert 'p' from 'vector<long long int>' to 'vector<int>'
   37 |         return p;
      |                ^
      |                |
      |                vector<long long int>