Submission #603213

# Submission time Handle Problem Language Result Execution time Memory
603213 2022-07-23T17:11:26 Z MohamedAhmed04 Uplifting Excursion (BOI22_vault) C++14
20 / 100
4952 ms 18700 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()
	{
		if(!q.size())
			while(1) ;
		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 ;
long long 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(abs(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 64 ms 15956 KB Output is correct
2 Correct 96 ms 15956 KB Output is correct
3 Correct 36 ms 15908 KB Output is correct
4 Correct 314 ms 15956 KB Output is correct
5 Correct 2633 ms 15956 KB Output is correct
6 Correct 2577 ms 15960 KB Output is correct
7 Correct 2496 ms 16020 KB Output is correct
8 Correct 2488 ms 15956 KB Output is correct
9 Correct 2595 ms 15960 KB Output is correct
10 Correct 2540 ms 15956 KB Output is correct
11 Correct 2565 ms 15956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 15956 KB Output is correct
2 Correct 96 ms 15956 KB Output is correct
3 Correct 36 ms 15908 KB Output is correct
4 Correct 314 ms 15956 KB Output is correct
5 Correct 2633 ms 15956 KB Output is correct
6 Correct 2577 ms 15960 KB Output is correct
7 Correct 2496 ms 16020 KB Output is correct
8 Correct 2488 ms 15956 KB Output is correct
9 Correct 2595 ms 15960 KB Output is correct
10 Correct 2540 ms 15956 KB Output is correct
11 Correct 2565 ms 15956 KB Output is correct
12 Correct 66 ms 15960 KB Output is correct
13 Correct 88 ms 15956 KB Output is correct
14 Correct 37 ms 15960 KB Output is correct
15 Correct 330 ms 15956 KB Output is correct
16 Correct 2611 ms 15960 KB Output is correct
17 Correct 2407 ms 15956 KB Output is correct
18 Correct 2624 ms 15960 KB Output is correct
19 Correct 2576 ms 15960 KB Output is correct
20 Correct 2592 ms 15956 KB Output is correct
21 Correct 2549 ms 15960 KB Output is correct
22 Correct 2642 ms 15956 KB Output is correct
23 Correct 4635 ms 15988 KB Output is correct
24 Correct 4601 ms 15960 KB Output is correct
25 Correct 4625 ms 15972 KB Output is correct
26 Correct 4580 ms 15956 KB Output is correct
27 Correct 4952 ms 15956 KB Output is correct
28 Correct 4647 ms 15960 KB Output is correct
29 Correct 4595 ms 15956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 353 ms 15960 KB Output is correct
2 Incorrect 1486 ms 18700 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 353 ms 15960 KB Output is correct
2 Incorrect 1486 ms 18700 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 353 ms 15960 KB Output is correct
2 Incorrect 1486 ms 18700 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 15956 KB Output is correct
2 Correct 96 ms 15956 KB Output is correct
3 Correct 36 ms 15908 KB Output is correct
4 Correct 314 ms 15956 KB Output is correct
5 Correct 2633 ms 15956 KB Output is correct
6 Correct 2577 ms 15960 KB Output is correct
7 Correct 2496 ms 16020 KB Output is correct
8 Correct 2488 ms 15956 KB Output is correct
9 Correct 2595 ms 15960 KB Output is correct
10 Correct 2540 ms 15956 KB Output is correct
11 Correct 2565 ms 15956 KB Output is correct
12 Correct 353 ms 15960 KB Output is correct
13 Incorrect 1486 ms 18700 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 353 ms 15960 KB Output is correct
2 Incorrect 1486 ms 18700 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 15956 KB Output is correct
2 Correct 96 ms 15956 KB Output is correct
3 Correct 36 ms 15908 KB Output is correct
4 Correct 314 ms 15956 KB Output is correct
5 Correct 2633 ms 15956 KB Output is correct
6 Correct 2577 ms 15960 KB Output is correct
7 Correct 2496 ms 16020 KB Output is correct
8 Correct 2488 ms 15956 KB Output is correct
9 Correct 2595 ms 15960 KB Output is correct
10 Correct 2540 ms 15956 KB Output is correct
11 Correct 2565 ms 15956 KB Output is correct
12 Correct 66 ms 15960 KB Output is correct
13 Correct 88 ms 15956 KB Output is correct
14 Correct 37 ms 15960 KB Output is correct
15 Correct 330 ms 15956 KB Output is correct
16 Correct 2611 ms 15960 KB Output is correct
17 Correct 2407 ms 15956 KB Output is correct
18 Correct 2624 ms 15960 KB Output is correct
19 Correct 2576 ms 15960 KB Output is correct
20 Correct 2592 ms 15956 KB Output is correct
21 Correct 2549 ms 15960 KB Output is correct
22 Correct 2642 ms 15956 KB Output is correct
23 Correct 4635 ms 15988 KB Output is correct
24 Correct 4601 ms 15960 KB Output is correct
25 Correct 4625 ms 15972 KB Output is correct
26 Correct 4580 ms 15956 KB Output is correct
27 Correct 4952 ms 15956 KB Output is correct
28 Correct 4647 ms 15960 KB Output is correct
29 Correct 4595 ms 15956 KB Output is correct
30 Correct 353 ms 15960 KB Output is correct
31 Incorrect 1486 ms 18700 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 353 ms 15960 KB Output is correct
2 Incorrect 1486 ms 18700 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 15956 KB Output is correct
2 Correct 96 ms 15956 KB Output is correct
3 Correct 36 ms 15908 KB Output is correct
4 Correct 314 ms 15956 KB Output is correct
5 Correct 2633 ms 15956 KB Output is correct
6 Correct 2577 ms 15960 KB Output is correct
7 Correct 2496 ms 16020 KB Output is correct
8 Correct 2488 ms 15956 KB Output is correct
9 Correct 2595 ms 15960 KB Output is correct
10 Correct 2540 ms 15956 KB Output is correct
11 Correct 2565 ms 15956 KB Output is correct
12 Correct 66 ms 15960 KB Output is correct
13 Correct 88 ms 15956 KB Output is correct
14 Correct 37 ms 15960 KB Output is correct
15 Correct 330 ms 15956 KB Output is correct
16 Correct 2611 ms 15960 KB Output is correct
17 Correct 2407 ms 15956 KB Output is correct
18 Correct 2624 ms 15960 KB Output is correct
19 Correct 2576 ms 15960 KB Output is correct
20 Correct 2592 ms 15956 KB Output is correct
21 Correct 2549 ms 15960 KB Output is correct
22 Correct 2642 ms 15956 KB Output is correct
23 Correct 4635 ms 15988 KB Output is correct
24 Correct 4601 ms 15960 KB Output is correct
25 Correct 4625 ms 15972 KB Output is correct
26 Correct 4580 ms 15956 KB Output is correct
27 Correct 4952 ms 15956 KB Output is correct
28 Correct 4647 ms 15960 KB Output is correct
29 Correct 4595 ms 15956 KB Output is correct
30 Correct 353 ms 15960 KB Output is correct
31 Incorrect 1486 ms 18700 KB Output isn't correct
32 Halted 0 ms 0 KB -