답안 #596358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
596358 2022-07-14T15:56:35 Z kshitij_sodani Uplifting Excursion (BOI22_vault) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define a first
#define b second
#define pb push_back
#define endl '\n'


llo n,dd;
llo it[350];

int cc[601];
int dp[2000001];
deque<pair<llo,llo>> zz[301];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>dd;

	llo cot=0;
	llo ma=0;
	for(llo i=0;i<n;i++){
		llo aa;
		cin>>aa;
		cot+=aa;
		cc[i]=aa;

	}
	llo su=0;
	for(llo i=0;i<=n;i++){
		cin>>it[i];
		su+=it[i]*i;
		cot+=it[i];
		cc[n+i]=i;
	}
	for(int i=0;i<=2*n;i++){
		ma=max(ma,cc[i]);
	}
	if(ma<=100 and n<=100){

		int xx=n*n*100;
		for(int i=0;i<=2*xx;i++){
			dp[i]=-1;
		}
		dp[xx]=0;
		for(int j=1;j<=n;j++){
			for(int jj=0;jj<j;jj++){
				zz[jj].clear();
			}
			llo ax=j*cc[n-j];
			int y=0;
			int z=0;
			for(int ii=0;ii<=2*xx;ii++){
			//	int y=ii%j;
				if(dp[ii]>=0){
					pair<int,int> cur={dp[ii]-z,ii};
					while(zz[y].size()){
						if(zz[y].back().a<=cur.a){
							zz[y].pop_back();
						}
						else{
							break;
						}
					}
					zz[y].pb(cur);
				}
				while(zz[y].size()){
					if(zz[y].front().b<ii-ax){
						zz[y].pop_front();
					}
					else{
						break;
					}
				}
				if(zz[y].size()){
					int xx=zz[y].front().a+z;
					dp[ii]=max(dp[ii],xx);
				}
				y++;
				if(y==j){
					y=0;
					z++;
				}
			}

		}
		/*for(int i=0;i<=2*xx;i++){
			if(dp[i]>=0){
				cout<<i-xx<<","<<dp[i]<<endl;
			}
		}*/
		for(int i=0;i<=xx;i++){
			swap(dp[xx+i],dp[xx-i]);
		}
		for(int j=1;j<=n;j++){
			for(int jj=0;jj<j;jj++){
				zz[jj].clear();
			}
			llo ax=j*it[j];
			int y=0;
			int z=0;
			for(int ii=0;ii<=2*xx;ii++){
			//	int y=ii%j;
				if(dp[ii]>=0){
					pair<int,int> cur={dp[ii]-z,ii};
					while(zz[y].size()){
						if(zz[y].back().a<=cur.a){
							zz[y].pop_back();
						}
						else{
							break;
						}
					}
					zz[y].pb(cur);
				}
				while(zz[y].size()){
					if(zz[y].front().b<ii-ax){
						zz[y].pop_front();
					}
					else{
						break;
					}
				}
				if(zz[y].size()){
					int xx=zz[y].front().a+z;
					dp[ii]=max(dp[ii],xx);
				}
				y++;
				if(y==j){
					y=0;
					z++;
				}
			}
		}

		if(dd>xx or dd<-xx){
			cout<<"impossible"<<endl;
			return 0;
		}
		if(dp[xx+dd]==-1){
			cout<<"impossible"<<endl;
			return 0;
		}
		llo ans=dp[xx+dd];
		ans+=it[0];
		cout<<ans<<endl;

		return 0;
	}
	if(su<dd){
		cout<<"impossible"<<endl;
		return 0;
	}
	llo cur=su-dd;
	it[0]=0;
	llo ans=-1;
	for(llo i=1;i<=n;i++){
		llo su2=0;
		llo ac=0;
		for(llo j=i+1;j<=n;j++){
			llo xx=it[j]-n;
			if(xx<0){
				xx=0;
			}
			ac+=xx;
			su2+=xx*j;
		}
		if(su2>cur){
			continue;
		}
		llo su3=0;//n*n*n;
		for(llo j=1;j<i;j++){
			su3+=j*min(it[j],i);
		}
		for(llo j=i+1;j<=n;j++){
			su3+=j*min(it[j],n);
		}

		for(llo j=0;j<=su3;j++){
			dp[j]=-1;
		}
		dp[0]=0;
		su3=0;
		for(int j=1;j<=n;j++){
			if(j==i){
				continue;
			}
			if(j<i){
				su3+=j*min(it[j],i);
			}
			else{
				su3+=j*min(it[j],n);
			}
			for(int jj=0;jj<j;jj++){
				zz[jj].clear();
			}
			llo ax=j*min(it[j],n);
			int y=0;
			int z=0;
			for(int ii=0;ii<=su3;ii++){
			//	int y=ii%j;
				if(dp[ii]>=0){
					pair<int,int> cur={dp[ii]-z,ii};
					while(zz[y].size()){
						if(zz[y].back().a>=cur.a){
							zz[y].pop_back();
						}
						else{
							break;
						}
					}
					zz[y].pb(cur);
				}
				while(zz[y].size()){
					if(zz[y].front().b<ii-ax){
						zz[y].pop_front();
					}
					else{
						break;
					}
				}
				if(zz[y].size()){
					int xx=zz[y].front().a+z;
					if(dp[ii]==-1){
						dp[ii]=xx;
					}
					dp[ii]=min(dp[ii],xx);
				}
				y++;
				if(y==j){
					y=0;
					z++;
				}
			}

		}

		llo cur2=cur-su2;

		for(llo j=cur2%i;j<=su3 and j<=cur2;j+=i){
			if(dp[j]>=0){
				//if((cur2-j)%i==0){
					llo x=(cur2-j)/i;
					if(x<=it[i]){
						llo y=dp[j]+x;
						y+=ac;
						if(ans==-1){
							ans=y;
						}
						ans=min(ans,y);
					}
				//}
			}
		}

	}
	if(ans==-1){
		cout<<"impossible"<<endl;
	}
	else{
		//cout<<ans<<endl;
		cout<<cot-ans<<endl;
	}

	//else find minimum number of elements with sum su-dd










	return 0;
}

Compilation message

vault.cpp: In function 'int main()':
vault.cpp:38:18: error: no matching function for call to 'max(llo&, int&)'
   38 |   ma=max(ma,cc[i]);
      |                  ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 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:38:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   38 |   ma=max(ma,cc[i]);
      |                  ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 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:38:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   38 |   ma=max(ma,cc[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 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:38:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   38 |   ma=max(ma,cc[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 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:38:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   38 |   ma=max(ma,cc[i]);
      |                  ^