제출 #953812

#제출 시각아이디문제언어결과실행 시간메모리
953812PM1Uplifting Excursion (BOI22_vault)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fr first #define sc second const int mxn=305; ll m,a[mxn*2],l,sum,ans,num; vector<pair<ll,ll>>v; ll dp[2][mxn*mxn*2]; void add(ll tedad,ll x,ll z){ tedad=(min(tedad,m*2)); for(ll i=1;i<=tedad;i*=2){ v.push_back({i*x,z*i}); tedad-=i; } if(tedad>0) v.push_back({tedad*x,z*tedad}); } void solve(){ for(ll i=m;i<2*m+1;i++){ ans+=a[i]; num+=a[i]*(i-m); add(a[i],-(i-m),-1); } ll i=m-1; for(;i>=0;i--){ if(num+a[i]*(i-m)>=l){ ans+=a[i]; num+=a[i]*(i-m); add(a[i],-(i-m),-1); continue; } ll x=l-num; x=x/(i-m); x=min(x,a[i]); num+=a[i]*x; ans+=x; add(x,-(i-m),-1); add(a[i]-x,i-m,1); i--; break; } for(;i>=0;i--){ add(a[i],(i-m),1); } } void solve1(){ for(ll i=m;i>=0;i--){ ans+=a[i]; num+=a[i]*(i-m); add(a[i],-(i-m),-1); } ll i=m+1; for(;i<m*2+1;i++){ if(num+a[i]*(i-m)<=l){ ans+=a[i]; num+=a[i]*(i-m); add(a[i],-(i-m),-1); continue; } ll x=l-num; x=x/(i-m); x=max(x,0); x=min(x,a[i]); num+=(i-m)*x; ans+=x; add(x,-(i-m),-1); add(a[i]-x,i-m,1); i++; break; } for(;i<m*2+1;i++){ add(a[i],(i-m),1); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>m>>l; for(ll i=0;i<m*2+1;i++){ cin>>a[i]; sum+=(i-m)*a[i]; } if(sum<=l) solve(); else solve1(); for(int i=0;i<=2*m*m;i++)dp[1][i]=-1e18; dp[1][m*m]=0; for(int i=0;i<v.size();i++){ ll x=v[i].fr,y=v[i].sc; int z=i&1; for(ll j=0;j<=2*m*m;j++){ if(j-x>=0 && j-x<=2*m*m && dp[z^1][j-x]!=-1e18) dp[z][j]=max(dp[z^1][j],dp[z^1][j-x]+y); else dp[z][j]=dp[z^1][j]; } //cout<<dp[z][928]<<" "; } int x=v.size()&1; x^=1; l-=num; if( l>m*m || l<-m*m ||dp[x][l+m*m]==-1e18 || ans+dp[x][l+m*m]<0){ cout<<"impossible"; return 0; } cout<<ans+dp[x][l+m*m]; return 0; }

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

vault.cpp: In function 'void solve1()':
vault.cpp:63:12: error: no matching function for call to 'max(long long int&, int)'
   63 |   x=max(x,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 vault.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:
vault.cpp:63:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   63 |   x=max(x,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 vault.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:
vault.cpp:63:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   63 |   x=max(x,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 vault.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:
vault.cpp:63:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   63 |   x=max(x,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 vault.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:
vault.cpp:63:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   63 |   x=max(x,0);
      |            ^
vault.cpp: In function 'int main()':
vault.cpp:92:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |  for(int i=0;i<v.size();i++){
      |              ~^~~~~~~~~