Submission #574885

# Submission time Handle Problem Language Result Execution time Memory
574885 2022-06-09T12:44:35 Z Jasiekstrz Uplifting Excursion (BOI22_vault) C++17
40 / 100
384 ms 3388 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;
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 1620 KB Output is correct
2 Correct 5 ms 1620 KB Output is correct
3 Correct 4 ms 1620 KB Output is correct
4 Correct 12 ms 1620 KB Output is correct
5 Runtime error 130 ms 3256 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1620 KB Output is correct
2 Correct 5 ms 1620 KB Output is correct
3 Correct 4 ms 1620 KB Output is correct
4 Correct 12 ms 1620 KB Output is correct
5 Runtime error 130 ms 3256 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1620 KB Output is correct
2 Correct 46 ms 1848 KB Output is correct
3 Correct 16 ms 1752 KB Output is correct
4 Correct 38 ms 2108 KB Output is correct
5 Correct 41 ms 1828 KB Output is correct
6 Correct 38 ms 2212 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 8 ms 1748 KB Output is correct
9 Correct 23 ms 1876 KB Output is correct
10 Correct 31 ms 1776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1620 KB Output is correct
2 Correct 46 ms 1848 KB Output is correct
3 Correct 16 ms 1752 KB Output is correct
4 Correct 38 ms 2108 KB Output is correct
5 Correct 41 ms 1828 KB Output is correct
6 Correct 38 ms 2212 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 8 ms 1748 KB Output is correct
9 Correct 23 ms 1876 KB Output is correct
10 Correct 31 ms 1776 KB Output is correct
11 Correct 7 ms 1620 KB Output is correct
12 Correct 5 ms 1620 KB Output is correct
13 Correct 3 ms 1620 KB Output is correct
14 Correct 12 ms 1620 KB Output is correct
15 Correct 44 ms 1844 KB Output is correct
16 Correct 13 ms 1748 KB Output is correct
17 Correct 39 ms 2004 KB Output is correct
18 Correct 42 ms 1824 KB Output is correct
19 Correct 41 ms 2212 KB Output is correct
20 Correct 4 ms 1748 KB Output is correct
21 Correct 9 ms 1748 KB Output is correct
22 Correct 24 ms 1940 KB Output is correct
23 Correct 30 ms 1736 KB Output is correct
24 Correct 81 ms 1844 KB Output is correct
25 Runtime error 31 ms 3388 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1620 KB Output is correct
2 Correct 46 ms 1848 KB Output is correct
3 Correct 16 ms 1752 KB Output is correct
4 Correct 38 ms 2108 KB Output is correct
5 Correct 41 ms 1828 KB Output is correct
6 Correct 38 ms 2212 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 8 ms 1748 KB Output is correct
9 Correct 23 ms 1876 KB Output is correct
10 Correct 31 ms 1776 KB Output is correct
11 Correct 12 ms 1620 KB Output is correct
12 Correct 41 ms 1748 KB Output is correct
13 Correct 15 ms 1748 KB Output is correct
14 Correct 38 ms 2004 KB Output is correct
15 Correct 40 ms 1732 KB Output is correct
16 Correct 38 ms 2216 KB Output is correct
17 Correct 4 ms 1748 KB Output is correct
18 Correct 9 ms 1748 KB Output is correct
19 Correct 25 ms 1876 KB Output is correct
20 Correct 30 ms 1732 KB Output is correct
21 Correct 5 ms 1620 KB Output is correct
22 Correct 8 ms 1620 KB Output is correct
23 Correct 75 ms 1800 KB Output is correct
24 Correct 29 ms 1736 KB Output is correct
25 Correct 74 ms 1864 KB Output is correct
26 Correct 63 ms 1876 KB Output is correct
27 Correct 65 ms 2100 KB Output is correct
28 Correct 51 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1620 KB Output is correct
2 Correct 5 ms 1620 KB Output is correct
3 Correct 4 ms 1620 KB Output is correct
4 Correct 12 ms 1620 KB Output is correct
5 Runtime error 130 ms 3256 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1620 KB Output is correct
2 Correct 46 ms 1848 KB Output is correct
3 Correct 16 ms 1752 KB Output is correct
4 Correct 38 ms 2108 KB Output is correct
5 Correct 41 ms 1828 KB Output is correct
6 Correct 38 ms 2212 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 8 ms 1748 KB Output is correct
9 Correct 23 ms 1876 KB Output is correct
10 Correct 31 ms 1776 KB Output is correct
11 Correct 12 ms 1620 KB Output is correct
12 Correct 41 ms 1748 KB Output is correct
13 Correct 15 ms 1748 KB Output is correct
14 Correct 38 ms 2004 KB Output is correct
15 Correct 40 ms 1732 KB Output is correct
16 Correct 38 ms 2216 KB Output is correct
17 Correct 4 ms 1748 KB Output is correct
18 Correct 9 ms 1748 KB Output is correct
19 Correct 25 ms 1876 KB Output is correct
20 Correct 30 ms 1732 KB Output is correct
21 Correct 5 ms 1620 KB Output is correct
22 Correct 8 ms 1620 KB Output is correct
23 Correct 75 ms 1800 KB Output is correct
24 Correct 29 ms 1736 KB Output is correct
25 Correct 74 ms 1864 KB Output is correct
26 Correct 63 ms 1876 KB Output is correct
27 Correct 65 ms 2100 KB Output is correct
28 Correct 51 ms 1748 KB Output is correct
29 Correct 13 ms 1620 KB Output is correct
30 Correct 44 ms 1748 KB Output is correct
31 Correct 14 ms 1748 KB Output is correct
32 Correct 40 ms 2004 KB Output is correct
33 Correct 42 ms 1788 KB Output is correct
34 Correct 39 ms 2132 KB Output is correct
35 Correct 6 ms 1844 KB Output is correct
36 Correct 10 ms 1748 KB Output is correct
37 Correct 26 ms 1948 KB Output is correct
38 Correct 34 ms 1732 KB Output is correct
39 Correct 5 ms 1620 KB Output is correct
40 Correct 9 ms 1620 KB Output is correct
41 Correct 79 ms 1748 KB Output is correct
42 Correct 45 ms 1764 KB Output is correct
43 Correct 71 ms 1876 KB Output is correct
44 Correct 67 ms 1932 KB Output is correct
45 Correct 70 ms 2100 KB Output is correct
46 Correct 52 ms 1796 KB Output is correct
47 Correct 4 ms 1620 KB Output is correct
48 Correct 9 ms 1620 KB Output is correct
49 Correct 138 ms 2108 KB Output is correct
50 Correct 57 ms 1736 KB Output is correct
51 Correct 131 ms 2132 KB Output is correct
52 Correct 141 ms 2020 KB Output is correct
53 Correct 126 ms 2108 KB Output is correct
54 Correct 124 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1620 KB Output is correct
2 Correct 5 ms 1620 KB Output is correct
3 Correct 4 ms 1620 KB Output is correct
4 Correct 12 ms 1620 KB Output is correct
5 Runtime error 130 ms 3256 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1620 KB Output is correct
2 Correct 46 ms 1848 KB Output is correct
3 Correct 16 ms 1752 KB Output is correct
4 Correct 38 ms 2108 KB Output is correct
5 Correct 41 ms 1828 KB Output is correct
6 Correct 38 ms 2212 KB Output is correct
7 Correct 4 ms 1748 KB Output is correct
8 Correct 8 ms 1748 KB Output is correct
9 Correct 23 ms 1876 KB Output is correct
10 Correct 31 ms 1776 KB Output is correct
11 Correct 12 ms 1620 KB Output is correct
12 Correct 41 ms 1748 KB Output is correct
13 Correct 15 ms 1748 KB Output is correct
14 Correct 38 ms 2004 KB Output is correct
15 Correct 40 ms 1732 KB Output is correct
16 Correct 38 ms 2216 KB Output is correct
17 Correct 4 ms 1748 KB Output is correct
18 Correct 9 ms 1748 KB Output is correct
19 Correct 25 ms 1876 KB Output is correct
20 Correct 30 ms 1732 KB Output is correct
21 Correct 5 ms 1620 KB Output is correct
22 Correct 8 ms 1620 KB Output is correct
23 Correct 75 ms 1800 KB Output is correct
24 Correct 29 ms 1736 KB Output is correct
25 Correct 74 ms 1864 KB Output is correct
26 Correct 63 ms 1876 KB Output is correct
27 Correct 65 ms 2100 KB Output is correct
28 Correct 51 ms 1748 KB Output is correct
29 Correct 13 ms 1620 KB Output is correct
30 Correct 44 ms 1748 KB Output is correct
31 Correct 14 ms 1748 KB Output is correct
32 Correct 40 ms 2004 KB Output is correct
33 Correct 42 ms 1788 KB Output is correct
34 Correct 39 ms 2132 KB Output is correct
35 Correct 6 ms 1844 KB Output is correct
36 Correct 10 ms 1748 KB Output is correct
37 Correct 26 ms 1948 KB Output is correct
38 Correct 34 ms 1732 KB Output is correct
39 Correct 5 ms 1620 KB Output is correct
40 Correct 9 ms 1620 KB Output is correct
41 Correct 79 ms 1748 KB Output is correct
42 Correct 45 ms 1764 KB Output is correct
43 Correct 71 ms 1876 KB Output is correct
44 Correct 67 ms 1932 KB Output is correct
45 Correct 70 ms 2100 KB Output is correct
46 Correct 52 ms 1796 KB Output is correct
47 Correct 4 ms 1620 KB Output is correct
48 Correct 9 ms 1620 KB Output is correct
49 Correct 138 ms 2108 KB Output is correct
50 Correct 57 ms 1736 KB Output is correct
51 Correct 131 ms 2132 KB Output is correct
52 Correct 141 ms 2020 KB Output is correct
53 Correct 126 ms 2108 KB Output is correct
54 Correct 124 ms 1876 KB Output is correct
55 Correct 15 ms 1620 KB Output is correct
56 Correct 50 ms 1732 KB Output is correct
57 Correct 14 ms 1748 KB Output is correct
58 Correct 46 ms 2004 KB Output is correct
59 Correct 47 ms 1824 KB Output is correct
60 Correct 38 ms 2132 KB Output is correct
61 Correct 5 ms 1840 KB Output is correct
62 Correct 8 ms 1732 KB Output is correct
63 Correct 25 ms 1876 KB Output is correct
64 Correct 35 ms 1740 KB Output is correct
65 Correct 6 ms 1728 KB Output is correct
66 Correct 10 ms 1620 KB Output is correct
67 Correct 71 ms 1804 KB Output is correct
68 Correct 34 ms 1748 KB Output is correct
69 Correct 65 ms 1876 KB Output is correct
70 Correct 71 ms 1876 KB Output is correct
71 Correct 58 ms 2100 KB Output is correct
72 Correct 51 ms 1788 KB Output is correct
73 Correct 5 ms 1620 KB Output is correct
74 Correct 8 ms 1732 KB Output is correct
75 Correct 131 ms 2108 KB Output is correct
76 Correct 58 ms 1736 KB Output is correct
77 Correct 126 ms 2132 KB Output is correct
78 Correct 128 ms 2028 KB Output is correct
79 Correct 112 ms 2108 KB Output is correct
80 Correct 110 ms 1876 KB Output is correct
81 Correct 382 ms 1876 KB Output is correct
82 Correct 178 ms 1748 KB Output is correct
83 Correct 384 ms 1760 KB Output is correct
84 Correct 364 ms 2124 KB Output is correct
85 Correct 4 ms 1736 KB Output is correct
86 Correct 8 ms 1620 KB Output is correct
87 Correct 324 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1620 KB Output is correct
2 Correct 5 ms 1620 KB Output is correct
3 Correct 4 ms 1620 KB Output is correct
4 Correct 12 ms 1620 KB Output is correct
5 Runtime error 130 ms 3256 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -