답안 #1063466

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063466 2024-08-17T19:01:25 Z deera 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

typedef int ll;


vector<ll> distribute_candies(vector<ll> c, vector<ll> l, vector<ll> r, vector<ll> v) {
    ll n = c.size(), q = v.size();

    bool non_neg = true;
    for (ll val: v) if (val < 0) {
        non_neg = false;
        break;
    }

    if (non_neg == true) {
        vector<ll> diff(n + 1, 0);

        for (ll i = 0; i < q; i++) {
            diff[l[i]] += v[i];
            diff[r[i] + 1] -= v[i];
        }

        for (ll i = 1; i < n; i++) {
            diff[i] += diff[i - 1];
        }

        vector<ll> res(n, 0);
        for (ll i = 0; i < n; i++) {
            res[i] = min(c[i], diff[i]);
        }

        return res;
    }

    if (n <= 2000 && q <= 2000) {
        vector<ll> res(n, 0);
        for (ll i = 0; i < q; i++) {
            for (ll j = l[i]; j <= r[i]; j++) {
                res[j] = max(min(res[j] + v[i], c[j]), 0ll);
            }
        }
        return res;
    }

    return vector<ll>();
}

signed main() {
    vector<ll> res = distribute_candies(vector<ll>({10ll, 10ll, 10ll, 10ll}), vector<ll>({0ll, 1ll}), vector<ll>({2ll, 1ll}), vector<ll>({7ll, 1ll}));

    for (ll i = 0; i < res.size(); i++)
        cout << res[i] << " ";
    cout << endl;
}

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:40:59: error: no matching function for call to 'max(const int&, long long int)'
   40 |                 res[j] = max(min(res[j] + v[i], c[j]), 0ll);
      |                                                           ^
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:40:59: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   40 |                 res[j] = max(min(res[j] + v[i], c[j]), 0ll);
      |                                                           ^
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:40:59: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   40 |                 res[j] = max(min(res[j] + v[i], c[j]), 0ll);
      |                                                           ^
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:40:59: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   40 |                 res[j] = max(min(res[j] + v[i], c[j]), 0ll);
      |                                                           ^
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:40:59: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   40 |                 res[j] = max(min(res[j] + v[i], c[j]), 0ll);
      |                                                           ^
candies.cpp: In function 'int main()':
candies.cpp:52:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (ll i = 0; i < res.size(); i++)
      |                    ~~^~~~~~~~~~~~