제출 #538630

#제출 시각아이디문제언어결과실행 시간메모리
538630chaoyue선물상자 (IOI15_boxes)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; #define ll long long ll delivery(int a, int b, int c, int p[]){ ll N = a, K = b, L = c, split = L/2, idx=0, lsize=1, rsize=1, f0, ans=0; vector<ll> left(N), right(N); left[0] = 0, right[0] = 0; while(idx < N && p[idx] <= split){ left[lsize] = p[idx] * 2; if(lsize >= K) left[lsize] += left[lsize-K]; idx++, lsize++; } while(idx < N){ right[rsize] = (L - p[idx]) * 2; if(rsize >= K) right[rsize] += right[rsize-K]; idx++, rsize++; } /*cout<<"left: "; for(int i=0; i<lsize; i++){ cout<<left[i]<<" "; } cout<<"\nright: "; for(int i=0; i<rsize; i++){ cout<<right[i]<<" "; } cout<<"\n";*/ //left is non-decreasing //pre array will flip left & right arrays vector<ll> lpre(lsize), rpre(rsize); lpre[0] = 0, rpre[0] = 0; for(ll i=1; i<lsize; i++){ lpre[i] = lpre[i-1] + left[lsize-i] - left[lsize-i-1]; } for(ll i=1; i<rsize; i++){ rpre[i] = rpre[i-1] + right[rsize-i] - right[rsize-i-i]; } /*cout<<"lpre: "; for(int i=0; i<lsize; i++){ cout<<lpre[i]<<" "; } cout<<"\nrpre: "; for(int i=0; i<rsize; i++){ cout<<rpre[i]<<" "; } cout<<"\n";*/ f0 = left[lsize-1] + right[rsize-1]; //initial answer if 0 loops vector<ll> opt(K); //calculates optimal value of lpre assuming rpre takes i souvenirs for(ll i=0; i<K; i++){ opt[i] = lpre[lsize-1] - ceil((lsize-1 + i) / K) * L; //if take everything if(i) opt[i] = max(opt[i], -L); //if take nothing else opt[i] = max(opt[i], 0); for(ll j=1; j*K-i<lsize; j++){ //takes care of middle part opt[i] = max(opt[i], lpre[j * K - i] - j * L); } } /*cout<<"opt: "; for(int i=0; i<K; i++){ cout<<opt[i]<<" "; } cout<<"\n";*/ for(int i=1; i<rsize; i++){ ans = max(ans, rpre[i] + opt[i%K] - i/K * L); } ans = min(f0, f0-ans); //cout<<f0<<"\n"; cout<<ans; return ans; }

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

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:53:54: warning: conversion from 'long long int' to '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'} may change value [-Wconversion]
   53 |   opt[i] = lpre[lsize-1] - ceil((lsize-1 + i) / K) * L;  //if take everything
      |                                                      ^
boxes.cpp:53:54: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'} may change value [-Wconversion]
boxes.cpp:53:26: warning: conversion from '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'} to '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} may change value [-Wfloat-conversion]
   53 |   opt[i] = lpre[lsize-1] - ceil((lsize-1 + i) / K) * L;  //if take everything
boxes.cpp:55:30: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int)'
   55 |   else opt[i] = max(opt[i], 0);
      |                              ^
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: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:
boxes.cpp:55:30: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   55 |   else opt[i] = max(opt[i], 0);
      |                              ^
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: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:
boxes.cpp:55:30: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   55 |   else opt[i] = max(opt[i], 0);
      |                              ^
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: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:
boxes.cpp:55:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   55 |   else opt[i] = max(opt[i], 0);
      |                              ^
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: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:
boxes.cpp:55:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   55 |   else opt[i] = max(opt[i], 0);
      |                              ^