답안 #574865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
574865 2022-06-09T12:39:23 Z Jasiekstrz Uplifting Excursion (BOI22_vault) C++17
0 / 100
64 ms 3276 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int M=300;
const long long INF=1e18L+7;
const int Z=M+10;
const int ZD=M*M+10;
long long t[2*Z+10];
vector<tuple<int,long long,int>> items;
long long dp[2*ZD+10];
deque<pair<int,long long>> q;
void addq(int j,long long c)
{
	while(!q.empty() && q.back().se<=c)
		q.pop_back();
	q.emplace_back(j,c);
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int m;
	long long l;
	cin>>m>>l;
	for(int i=-m;i<=m;i++)
		cin>>t[Z+i];
	if(l<0)
	{
		l=-l;
		for(int i=1;i<=m;i++)
			swap(t[Z-i],t[Z+i]);
	}
	long long ans=0;
	long long s=0;
	for(int i=-m;i<=m;i++)
	{
		long long tmp;
		if(i<=0)
			tmp=t[Z+i];
		else
			tmp=min(t[Z+i],(l-s)/i);

		if(tmp>0)
		{
			ans+=tmp;
			s+=tmp*i;
			items.emplace_back(-i,tmp,-1);
		}
		if(tmp<t[Z+i])
			items.emplace_back(i,t[Z+i]-tmp,1);
	}
	for(int i=0;i<=2*ZD;i++)
		dp[i]=-INF;
	dp[ZD]=ans;
	for(auto [v,cnt,c]:items)
	{
		if(v>0)
		{
			for(int r=0;r<v;r++)
			{
				q.clear();
				for(int i=r,j=0;i<=2*ZD;i+=v,j++)
				{
					addq(j,dp[i]-j*c);
					if(q.front().fi+cnt<j)
						q.pop_front();

					dp[i]=q.front().se+j*c;
				}
			}
		}
		else
		{
			for(int r=2*ZD;r>2*ZD-v;r--)
			{
				q.clear();
				for(int i=r,j=0;i>=0;i+=v,j++)
				{
					addq(j,dp[i]-j*c);
					if(q.front().fi+cnt<j)
						q.pop_front();

					dp[i]=q.front().se+j*c;
				}
			}
		}
	}
	if(dp[ZD+l-s]<0)
		cout<<"impossible\n";
	else
		cout<<dp[ZD+l-s]<<"\n";
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1620 KB Output is correct
2 Correct 3 ms 1620 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 12 ms 1632 KB Output is correct
5 Runtime error 64 ms 3276 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1620 KB Output is correct
2 Correct 3 ms 1620 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 12 ms 1632 KB Output is correct
5 Runtime error 64 ms 3276 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1620 KB Output is correct
2 Incorrect 5 ms 1620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1620 KB Output is correct
2 Incorrect 5 ms 1620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1620 KB Output is correct
2 Incorrect 5 ms 1620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1620 KB Output is correct
2 Correct 3 ms 1620 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 12 ms 1632 KB Output is correct
5 Runtime error 64 ms 3276 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1620 KB Output is correct
2 Incorrect 5 ms 1620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1620 KB Output is correct
2 Correct 3 ms 1620 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 12 ms 1632 KB Output is correct
5 Runtime error 64 ms 3276 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1620 KB Output is correct
2 Incorrect 5 ms 1620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1620 KB Output is correct
2 Correct 3 ms 1620 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 12 ms 1632 KB Output is correct
5 Runtime error 64 ms 3276 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -