Submission #603210

# Submission time Handle Problem Language Result Execution time Memory
603210 2022-07-23T17:09:00 Z MohamedAhmed04 Uplifting Excursion (BOI22_vault) C++14
0 / 100
2566 ms 32084 KB
#include <bits/stdc++.h>

using namespace std ;

struct Max_queue
{

deque< pair<int , int> >q ;
public:
	void insert(int val , int idx)
	{
		while(!q.empty() && val >= q.back().first)
			q.pop_back() ;
		q.emplace_back(val , idx) ;
	}

	void erase(int idx)
	{
		if(q.front().second == idx)
			q.pop_front() ;
	}

	int Max()
	{
		return (q.front().first) ;
	}

	void clear()
	{
		q.clear() ;
	}
};

const int MAX = 100 + 10 ;
const int ZERO = 1e6 ;
const int MAX2 = 2e6 + 10 ;

int arr[2*MAX] ;
int n , l ;

int dp[2][MAX2] ;

Max_queue q ;

multiset<int>s ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>l ;
	for(int i = -n ; i <= n ; ++i)
		cin>>arr[i+n] ;
	for(int i = 0 ; i <= 2e6 ; ++i)
		dp[0][i] = -1e9 ;
	dp[0][ZERO] = 0 ;
	int now = 0 , prv = 1 ;
	for(int i = -n ; i < 0 ; ++i)
	{
		now = !now , prv = !prv ;
		for(int j = 0 ; j < i*-1 ; ++j)
		{
			q.clear() ;
			int cur = 0 ;
			for(int k = 2e6-j ; k >= 0 ; k -= i*-1)
			{
				q.insert(dp[prv][k] - cur , k) ;
				int a = k + (arr[i+n]+1) * (i*-1) ;
				if(cur > arr[i+n])
					q.erase(a) ;
				dp[now][k] = cur + q.Max() ;
				++cur ;
			}
		}
	}
	for(int i = 1 ; i <= n ; ++i)
	{
		now = !now , prv = !prv ;
		for(int j = 0 ; j < i ; ++j)
		{
			q.clear() ;
			int cur = 0 ;
			for(int k = j ; k <= 2e6 ; k += i)
			{
				q.insert(dp[prv][k] - cur , k) ;
				int a = k - (arr[i+n]+1) * i ;
				if(cur > arr[i+n])
					q.erase(a) ;
				dp[now][k] = cur + q.Max() ;
				++cur ;
			}
		}
	}
	if(l <= 1e6 && dp[now][ZERO+l] + arr[n] >= 0)
		cout<<dp[now][ZERO+l] + arr[n]<<"\n" ;
	else
		cout<<"impossible\n" ;
	return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 48 ms 15956 KB Output is correct
2 Correct 73 ms 15984 KB Output is correct
3 Correct 32 ms 15872 KB Output is correct
4 Correct 272 ms 15956 KB Output is correct
5 Runtime error 2566 ms 32084 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 15956 KB Output is correct
2 Correct 73 ms 15984 KB Output is correct
3 Correct 32 ms 15872 KB Output is correct
4 Correct 272 ms 15956 KB Output is correct
5 Runtime error 2566 ms 32084 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 237 ms 15956 KB Output is correct
2 Incorrect 1237 ms 15960 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 237 ms 15956 KB Output is correct
2 Incorrect 1237 ms 15960 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 237 ms 15956 KB Output is correct
2 Incorrect 1237 ms 15960 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 15956 KB Output is correct
2 Correct 73 ms 15984 KB Output is correct
3 Correct 32 ms 15872 KB Output is correct
4 Correct 272 ms 15956 KB Output is correct
5 Runtime error 2566 ms 32084 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 237 ms 15956 KB Output is correct
2 Incorrect 1237 ms 15960 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 15956 KB Output is correct
2 Correct 73 ms 15984 KB Output is correct
3 Correct 32 ms 15872 KB Output is correct
4 Correct 272 ms 15956 KB Output is correct
5 Runtime error 2566 ms 32084 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 237 ms 15956 KB Output is correct
2 Incorrect 1237 ms 15960 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 15956 KB Output is correct
2 Correct 73 ms 15984 KB Output is correct
3 Correct 32 ms 15872 KB Output is correct
4 Correct 272 ms 15956 KB Output is correct
5 Runtime error 2566 ms 32084 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -