Submission #745196

# Submission time Handle Problem Language Result Execution time Memory
745196 2023-05-19T14:32:39 Z 박상훈(#9964) Uplifting Excursion (BOI22_vault) C++17
45 / 100
1507 ms 820 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
constexpr int SFT = 5050;
int n;
ll L, a[1010], b[1010];
bitset<10010> dp[2][606];

// struct BITSET{
// 	unsigned long long bt[MX+1]; //bt[sz] should be 0
// 	int sz; //size < MX
// }dp[2][606];

// void _bit_on(BITSET &B, int pos){
// 	if ((pos>>6) >= sz){
// 		for (int i=sz+1;i<=(pos>>6)+1;i++) bt[i] = 0;
// 		sz = (pos>>6)+1;
// 	}
// 	B.bt[pos>>6] |= 1LL<<(pos&63);
// }

// bool _chk_on(BITSET &B, int pos){
// 	return ((pos>>6) < sz) && (B.bt[pos>>6] & (1LL<<(pos&63)));
// }

// void _shift_or(BITSET &prv, BITSET &now, int sft){
// 	now.sz = prv.sz;
// 	for (int i=0;i<=sz;i++) now.bt[i] = prv.bt[i];


// }

ll getmin(ll v, bool flag = 0){
	ll ret = 0;
	for (int i=-n;i<=n;i++){
		ret += (ll)i * min(v, a[i+n]);
		if (flag) b[i+n] = min(v, a[i+n]);
		v -= min(v, a[i+n]);
	}
	return ret;
}

ll getmax(ll v, bool flag = 0){
	ll ret = 0;
	for (int i=n;i>=-n;i--){
		ret += (ll)i * min(v, a[i+n]);
		if (flag) b[i+n] = min(v, a[i+n]);
		v -= min(v, a[i+n]);
	}
	return ret;
}

void NO(){
	printf("impossible\n");
	exit(0);
}

void solve(ll v){
	ll mn = getmin(v), mx = getmax(v);
	if (abs(mn-L) > n && abs(mx-L) > n) assert(0);
	if (abs(mn-L) <= n){
		reverse(a, a+n*2+1);
		L = -L;
		mn = getmin(v), mx = getmax(v);
		if (abs(mn-L) > n && abs(mx-L) > n) assert(0);
	}
	getmax(v, 1);

	int z = 0;
	ll r = n*2+2;
	
	//init
	// _bit_on(dp[0][0], 0);
	dp[0][0][0+SFT] = 1;

	for (int i=n;i>=-n;i--){
		if (b[i+n] > 0){
			for (int j=1;j<=min(b[i+n], r);j++){
				z ^= 1;
				for (int p=-1;p<r;p++){
					// _shift_or(dp[z^1][p], dp[z][p+1], i);
					
					if (p+1 < j) dp[z][p+1] = dp[z^1][p+1];
					else if (i>=0) dp[z][p+1] = dp[z^1][p+1] | (dp[z^1][p] << i);
					else dp[z][p+1] = dp[z^1][p+1] | (dp[z^1][p] >> (-i));
					
					// printf("i = %d, j = %d, p+1 = %d -> ", i, j, p+1);
					// for (int x=-20;x<20;x++){
					// 	if (x==0) printf(" ");
					// 	printf("%d", (int)dp[z][p+1][x+SFT]);
					// } 
					// printf("\n");
				}
			}
		}

		if (b[i+n] < a[i+n]){
			for (int j=1;j<=min(a[i+n]-b[i+n], r);j++){
				z ^= 1;
				for (int p=1;p<=r+1;p++){
					// _shift_or(dp[z^1][p], dp[z][p-1], -i);
					
					if (r-p+1 < j) dp[z][p-1] = dp[z^1][p-1];
					else if (i>=0) dp[z][p-1] = dp[z^1][p-1] | (dp[z^1][p] >> i);
					else dp[z][p-1] = dp[z^1][p-1] | (dp[z^1][p] << (-i));
					
					// printf("i = %d, j = %d, p-1 = %d -> ", i, j, p-1);
					// for (int x=-20;x<20;x++){
					// 	if (x==0) printf(" ");
					// 	printf("%d", (int)dp[z][p-1][x+SFT]);
					// } 
					// printf("\n");
				}
			}
		}
	}

	ll need = mx - L;
	for (int i=0;i<=r;i++) if (dp[z][i][need+SFT]){
		printf("%lld\n", v-i);
		return;
	}
	NO();
}

int main(){
	scanf("%d %lld", &n, &L);

	ll mS = 0, pS = 0, S = 0;
	for (int i=0;i<=n*2;i++){
		scanf("%lld", a+i);
		S += a[i];
		if (i-n < 0) mS += a[i];
		else if (i-n > 0) pS += a[i];
	} 

	// printf("%lld %lld %lld %lld\n", mS, pS, getmin(mS), getmax(pS));
	if (L < getmin(mS)) NO();
	if (L > getmax(pS)) NO();

	ll l = mS, r = S, vmn = mS;
	while(l<=r){
		ll mid = (l+r)/2;
		if (getmin(mid) <= L) vmn = mid, l = mid+1;
		else r = mid-1;
	}

	l = pS, r = S;
	ll vmx = pS;
	while(l<=r){
		ll mid = (l+r)/2;
		if (getmax(mid) >= L) vmx = mid, l = mid+1;
		else r = mid-1;
	}

	ll v = min(vmn, vmx); // [v+1, S]는 불가능
	// printf("%lld(%lld, %lld) -> %lld %lld\n", v, vmn, vmx, getmin(v), getmax(v));
	if (!(getmin(v) <= L) || !(getmax(v) >= L)) NO();
	solve(v);
}

Compilation message

vault.cpp: In function 'int main()':
vault.cpp:128:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |  scanf("%d %lld", &n, &L);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
vault.cpp:132:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |   scanf("%lld", a+i);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 109 ms 552 KB Output is correct
7 Correct 44 ms 552 KB Output is correct
8 Correct 105 ms 568 KB Output is correct
9 Correct 181 ms 468 KB Output is correct
10 Correct 5 ms 468 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 109 ms 552 KB Output is correct
7 Correct 44 ms 552 KB Output is correct
8 Correct 105 ms 568 KB Output is correct
9 Correct 181 ms 468 KB Output is correct
10 Correct 5 ms 468 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 116 ms 552 KB Output is correct
18 Correct 43 ms 468 KB Output is correct
19 Correct 105 ms 556 KB Output is correct
20 Correct 180 ms 552 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 833 ms 800 KB Output is correct
25 Correct 286 ms 800 KB Output is correct
26 Correct 1507 ms 800 KB Output is correct
27 Correct 1497 ms 800 KB Output is correct
28 Incorrect 20 ms 820 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 21 ms 472 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 23 ms 468 KB Output is correct
5 Correct 25 ms 476 KB Output is correct
6 Correct 15 ms 468 KB Output is correct
7 Correct 5 ms 476 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 9 ms 476 KB Output is correct
10 Correct 15 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 21 ms 472 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 23 ms 468 KB Output is correct
5 Correct 25 ms 476 KB Output is correct
6 Correct 15 ms 468 KB Output is correct
7 Correct 5 ms 476 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 9 ms 476 KB Output is correct
10 Correct 15 ms 476 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 20 ms 476 KB Output is correct
16 Correct 6 ms 468 KB Output is correct
17 Correct 23 ms 468 KB Output is correct
18 Correct 26 ms 468 KB Output is correct
19 Correct 16 ms 468 KB Output is correct
20 Correct 4 ms 468 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 8 ms 468 KB Output is correct
23 Correct 19 ms 476 KB Output is correct
24 Correct 39 ms 468 KB Output is correct
25 Correct 14 ms 480 KB Output is correct
26 Correct 48 ms 468 KB Output is correct
27 Correct 37 ms 468 KB Output is correct
28 Correct 41 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 21 ms 472 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 23 ms 468 KB Output is correct
5 Correct 25 ms 476 KB Output is correct
6 Correct 15 ms 468 KB Output is correct
7 Correct 5 ms 476 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 9 ms 476 KB Output is correct
10 Correct 15 ms 476 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 20 ms 468 KB Output is correct
13 Correct 9 ms 468 KB Output is correct
14 Correct 23 ms 472 KB Output is correct
15 Correct 25 ms 480 KB Output is correct
16 Correct 17 ms 480 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 10 ms 480 KB Output is correct
20 Correct 16 ms 476 KB Output is correct
21 Correct 5 ms 468 KB Output is correct
22 Correct 4 ms 576 KB Output is correct
23 Correct 79 ms 468 KB Output is correct
24 Correct 41 ms 468 KB Output is correct
25 Correct 87 ms 552 KB Output is correct
26 Correct 114 ms 552 KB Output is correct
27 Correct 83 ms 468 KB Output is correct
28 Correct 77 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 109 ms 552 KB Output is correct
7 Correct 44 ms 552 KB Output is correct
8 Correct 105 ms 568 KB Output is correct
9 Correct 181 ms 468 KB Output is correct
10 Correct 5 ms 468 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 21 ms 472 KB Output is correct
14 Correct 6 ms 468 KB Output is correct
15 Correct 23 ms 468 KB Output is correct
16 Correct 25 ms 476 KB Output is correct
17 Correct 15 ms 468 KB Output is correct
18 Correct 5 ms 476 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 9 ms 476 KB Output is correct
21 Correct 15 ms 476 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 20 ms 476 KB Output is correct
27 Correct 6 ms 468 KB Output is correct
28 Correct 23 ms 468 KB Output is correct
29 Correct 26 ms 468 KB Output is correct
30 Correct 16 ms 468 KB Output is correct
31 Correct 4 ms 468 KB Output is correct
32 Correct 3 ms 468 KB Output is correct
33 Correct 8 ms 468 KB Output is correct
34 Correct 19 ms 476 KB Output is correct
35 Correct 39 ms 468 KB Output is correct
36 Correct 14 ms 480 KB Output is correct
37 Correct 48 ms 468 KB Output is correct
38 Correct 37 ms 468 KB Output is correct
39 Correct 41 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 20 ms 468 KB Output is correct
42 Correct 9 ms 468 KB Output is correct
43 Correct 23 ms 472 KB Output is correct
44 Correct 25 ms 480 KB Output is correct
45 Correct 17 ms 480 KB Output is correct
46 Correct 4 ms 468 KB Output is correct
47 Correct 3 ms 468 KB Output is correct
48 Correct 10 ms 480 KB Output is correct
49 Correct 16 ms 476 KB Output is correct
50 Correct 5 ms 468 KB Output is correct
51 Correct 4 ms 576 KB Output is correct
52 Correct 79 ms 468 KB Output is correct
53 Correct 41 ms 468 KB Output is correct
54 Correct 87 ms 552 KB Output is correct
55 Correct 114 ms 552 KB Output is correct
56 Correct 83 ms 468 KB Output is correct
57 Correct 77 ms 468 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 109 ms 468 KB Output is correct
64 Correct 42 ms 468 KB Output is correct
65 Correct 104 ms 468 KB Output is correct
66 Correct 173 ms 468 KB Output is correct
67 Correct 5 ms 468 KB Output is correct
68 Correct 4 ms 468 KB Output is correct
69 Correct 20 ms 468 KB Output is correct
70 Correct 6 ms 476 KB Output is correct
71 Correct 22 ms 476 KB Output is correct
72 Correct 27 ms 468 KB Output is correct
73 Correct 15 ms 476 KB Output is correct
74 Correct 4 ms 468 KB Output is correct
75 Correct 4 ms 468 KB Output is correct
76 Correct 9 ms 476 KB Output is correct
77 Correct 15 ms 472 KB Output is correct
78 Correct 40 ms 468 KB Output is correct
79 Correct 15 ms 468 KB Output is correct
80 Correct 49 ms 468 KB Output is correct
81 Correct 37 ms 592 KB Output is correct
82 Correct 43 ms 468 KB Output is correct
83 Correct 79 ms 552 KB Output is correct
84 Correct 42 ms 468 KB Output is correct
85 Correct 81 ms 468 KB Output is correct
86 Correct 114 ms 556 KB Output is correct
87 Correct 96 ms 548 KB Output is correct
88 Correct 79 ms 564 KB Output is correct
89 Correct 145 ms 468 KB Output is correct
90 Correct 213 ms 468 KB Output is correct
91 Correct 154 ms 468 KB Output is correct
92 Correct 167 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 21 ms 472 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 23 ms 468 KB Output is correct
5 Correct 25 ms 476 KB Output is correct
6 Correct 15 ms 468 KB Output is correct
7 Correct 5 ms 476 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 9 ms 476 KB Output is correct
10 Correct 15 ms 476 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 20 ms 468 KB Output is correct
13 Correct 9 ms 468 KB Output is correct
14 Correct 23 ms 472 KB Output is correct
15 Correct 25 ms 480 KB Output is correct
16 Correct 17 ms 480 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 10 ms 480 KB Output is correct
20 Correct 16 ms 476 KB Output is correct
21 Correct 5 ms 468 KB Output is correct
22 Correct 4 ms 576 KB Output is correct
23 Correct 79 ms 468 KB Output is correct
24 Correct 41 ms 468 KB Output is correct
25 Correct 87 ms 552 KB Output is correct
26 Correct 114 ms 552 KB Output is correct
27 Correct 83 ms 468 KB Output is correct
28 Correct 77 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 21 ms 468 KB Output is correct
31 Correct 7 ms 468 KB Output is correct
32 Correct 24 ms 468 KB Output is correct
33 Correct 25 ms 468 KB Output is correct
34 Correct 16 ms 468 KB Output is correct
35 Correct 4 ms 476 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 8 ms 480 KB Output is correct
38 Correct 15 ms 468 KB Output is correct
39 Correct 5 ms 468 KB Output is correct
40 Correct 4 ms 568 KB Output is correct
41 Correct 83 ms 556 KB Output is correct
42 Correct 44 ms 588 KB Output is correct
43 Correct 81 ms 468 KB Output is correct
44 Correct 114 ms 556 KB Output is correct
45 Correct 88 ms 556 KB Output is correct
46 Correct 78 ms 556 KB Output is correct
47 Incorrect 24 ms 724 KB Output isn't correct
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 109 ms 552 KB Output is correct
7 Correct 44 ms 552 KB Output is correct
8 Correct 105 ms 568 KB Output is correct
9 Correct 181 ms 468 KB Output is correct
10 Correct 5 ms 468 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 116 ms 552 KB Output is correct
18 Correct 43 ms 468 KB Output is correct
19 Correct 105 ms 556 KB Output is correct
20 Correct 180 ms 552 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 833 ms 800 KB Output is correct
25 Correct 286 ms 800 KB Output is correct
26 Correct 1507 ms 800 KB Output is correct
27 Correct 1497 ms 800 KB Output is correct
28 Incorrect 20 ms 820 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 21 ms 472 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 23 ms 468 KB Output is correct
5 Correct 25 ms 476 KB Output is correct
6 Correct 15 ms 468 KB Output is correct
7 Correct 5 ms 476 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 9 ms 476 KB Output is correct
10 Correct 15 ms 476 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 20 ms 468 KB Output is correct
13 Correct 9 ms 468 KB Output is correct
14 Correct 23 ms 472 KB Output is correct
15 Correct 25 ms 480 KB Output is correct
16 Correct 17 ms 480 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 3 ms 468 KB Output is correct
19 Correct 10 ms 480 KB Output is correct
20 Correct 16 ms 476 KB Output is correct
21 Correct 5 ms 468 KB Output is correct
22 Correct 4 ms 576 KB Output is correct
23 Correct 79 ms 468 KB Output is correct
24 Correct 41 ms 468 KB Output is correct
25 Correct 87 ms 552 KB Output is correct
26 Correct 114 ms 552 KB Output is correct
27 Correct 83 ms 468 KB Output is correct
28 Correct 77 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 21 ms 468 KB Output is correct
31 Correct 7 ms 468 KB Output is correct
32 Correct 24 ms 468 KB Output is correct
33 Correct 25 ms 468 KB Output is correct
34 Correct 16 ms 468 KB Output is correct
35 Correct 4 ms 476 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 8 ms 480 KB Output is correct
38 Correct 15 ms 468 KB Output is correct
39 Correct 5 ms 468 KB Output is correct
40 Correct 4 ms 568 KB Output is correct
41 Correct 83 ms 556 KB Output is correct
42 Correct 44 ms 588 KB Output is correct
43 Correct 81 ms 468 KB Output is correct
44 Correct 114 ms 556 KB Output is correct
45 Correct 88 ms 556 KB Output is correct
46 Correct 78 ms 556 KB Output is correct
47 Incorrect 24 ms 724 KB Output isn't correct
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 109 ms 552 KB Output is correct
7 Correct 44 ms 552 KB Output is correct
8 Correct 105 ms 568 KB Output is correct
9 Correct 181 ms 468 KB Output is correct
10 Correct 5 ms 468 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 116 ms 552 KB Output is correct
18 Correct 43 ms 468 KB Output is correct
19 Correct 105 ms 556 KB Output is correct
20 Correct 180 ms 552 KB Output is correct
21 Correct 4 ms 468 KB Output is correct
22 Correct 5 ms 468 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 833 ms 800 KB Output is correct
25 Correct 286 ms 800 KB Output is correct
26 Correct 1507 ms 800 KB Output is correct
27 Correct 1497 ms 800 KB Output is correct
28 Incorrect 20 ms 820 KB Output isn't correct
29 Halted 0 ms 0 KB -