답안 #1070978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070978 2024-08-22T22:12:14 Z AdamGS Uplifting Excursion (BOI22_vault) C++17
40 / 100
4477 ms 72656 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e18+7;
const ll LIM=1e6+7;
vector<int>V[LIM];
ll dp[LIM], dp2[LIM], A[LIM], B[LIM], l[LIM], sz[LIM];
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n, m;
	cin >> n >> m;
	rep(i, n) cin >> A[n-i];
	rep(i, n+1) cin >> B[i];
	ll ans=0;
	rep(i, n+1) ans+=B[i];
	rep(i, n+1) ans+=A[i];
	rep(i, n+1) m+=A[i]*(ll)i;
	rep(i, n+1) m-=B[i]*(ll)i;
	if(m<0) {
		m*=-1;
		rep(i, n+1) swap(A[i], B[i]);
	}
	rep(i, LIM) dp[i]=INF;
	dp[0]=0;
	int ile=1;
	for(ll i=n; i; --i) {
		if(m>=LIM/2) {
			ll p=m-LIM/2;
			p=(p+i-1)/i;
			p=min(p, max(A[i]-300/ile, 0ll));
			A[i]-=p;
			if(A[i]) ++ile;
			dp[0]+=p;
			m-=p*i;	
		}
	}
	if(m>=LIM) {
		cout << "impossible\n";
		return 0;
	}
	for(int i=1; i<=n; ++i) rep(j, LIM/i+1) V[i-1].pb(0);
	rep(xd, 2) {
		for(ll i=1; i<=n; ++i) if(A[i]) {
			rep(j, i) l[j]=sz[j]=0;
			rep(j, LIM-LIM/2*xd) {
				ll p=j%i;
				while(l[p]<sz[p] && (j-V[p][l[p]])/i>A[i]) ++l[p];
				while(sz[p]>0 && dp[j]<=dp[V[p][sz[p]-1]]+(j-V[p][sz[p]-1])/i) {
					--sz[p];
					l[p]=min(l[p], sz[p]);
				}
				dp2[j]=dp[j];
				if(l[p]<sz[p]) dp2[j]=min(dp2[j], dp[V[p][l[p]]]+(j-V[p][l[p]])/i);
				V[p][sz[p]]=j;
				++sz[p];
			}
			rep(j, LIM) dp[j]=dp2[j];
		}
		rep(i, LIM/2) swap(dp[i], dp[LIM-i-1]);
		rep(i, n+1) swap(A[i], B[i]);
	}
	if(dp[m]==INF) {
		cout << "impossible\n";
		return 0;
	}
	cout << ans-dp[m] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 53960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 53960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 58060 KB Output is correct
2 Correct 420 ms 62200 KB Output is correct
3 Correct 132 ms 62156 KB Output is correct
4 Correct 430 ms 62396 KB Output is correct
5 Correct 434 ms 62200 KB Output is correct
6 Correct 479 ms 62136 KB Output is correct
7 Correct 46 ms 62040 KB Output is correct
8 Correct 71 ms 61960 KB Output is correct
9 Correct 278 ms 62404 KB Output is correct
10 Correct 311 ms 62156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 58060 KB Output is correct
2 Correct 420 ms 62200 KB Output is correct
3 Correct 132 ms 62156 KB Output is correct
4 Correct 430 ms 62396 KB Output is correct
5 Correct 434 ms 62200 KB Output is correct
6 Correct 479 ms 62136 KB Output is correct
7 Correct 46 ms 62040 KB Output is correct
8 Correct 71 ms 61960 KB Output is correct
9 Correct 278 ms 62404 KB Output is correct
10 Correct 311 ms 62156 KB Output is correct
11 Incorrect 41 ms 53968 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 58060 KB Output is correct
2 Correct 420 ms 62200 KB Output is correct
3 Correct 132 ms 62156 KB Output is correct
4 Correct 430 ms 62396 KB Output is correct
5 Correct 434 ms 62200 KB Output is correct
6 Correct 479 ms 62136 KB Output is correct
7 Correct 46 ms 62040 KB Output is correct
8 Correct 71 ms 61960 KB Output is correct
9 Correct 278 ms 62404 KB Output is correct
10 Correct 311 ms 62156 KB Output is correct
11 Correct 115 ms 58176 KB Output is correct
12 Correct 425 ms 62200 KB Output is correct
13 Correct 132 ms 62400 KB Output is correct
14 Correct 432 ms 62200 KB Output is correct
15 Correct 427 ms 62396 KB Output is correct
16 Correct 454 ms 62204 KB Output is correct
17 Correct 45 ms 62152 KB Output is correct
18 Correct 74 ms 62200 KB Output is correct
19 Correct 271 ms 62160 KB Output is correct
20 Correct 307 ms 62924 KB Output is correct
21 Correct 42 ms 63936 KB Output is correct
22 Correct 71 ms 64140 KB Output is correct
23 Correct 726 ms 64144 KB Output is correct
24 Correct 318 ms 63952 KB Output is correct
25 Correct 728 ms 64080 KB Output is correct
26 Correct 722 ms 63952 KB Output is correct
27 Correct 766 ms 63944 KB Output is correct
28 Correct 546 ms 63952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 53960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 58060 KB Output is correct
2 Correct 420 ms 62200 KB Output is correct
3 Correct 132 ms 62156 KB Output is correct
4 Correct 430 ms 62396 KB Output is correct
5 Correct 434 ms 62200 KB Output is correct
6 Correct 479 ms 62136 KB Output is correct
7 Correct 46 ms 62040 KB Output is correct
8 Correct 71 ms 61960 KB Output is correct
9 Correct 278 ms 62404 KB Output is correct
10 Correct 311 ms 62156 KB Output is correct
11 Correct 115 ms 58176 KB Output is correct
12 Correct 425 ms 62200 KB Output is correct
13 Correct 132 ms 62400 KB Output is correct
14 Correct 432 ms 62200 KB Output is correct
15 Correct 427 ms 62396 KB Output is correct
16 Correct 454 ms 62204 KB Output is correct
17 Correct 45 ms 62152 KB Output is correct
18 Correct 74 ms 62200 KB Output is correct
19 Correct 271 ms 62160 KB Output is correct
20 Correct 307 ms 62924 KB Output is correct
21 Correct 42 ms 63936 KB Output is correct
22 Correct 71 ms 64140 KB Output is correct
23 Correct 726 ms 64144 KB Output is correct
24 Correct 318 ms 63952 KB Output is correct
25 Correct 728 ms 64080 KB Output is correct
26 Correct 722 ms 63952 KB Output is correct
27 Correct 766 ms 63944 KB Output is correct
28 Correct 546 ms 63952 KB Output is correct
29 Correct 110 ms 58064 KB Output is correct
30 Correct 423 ms 62152 KB Output is correct
31 Correct 133 ms 62200 KB Output is correct
32 Correct 416 ms 62916 KB Output is correct
33 Correct 420 ms 61956 KB Output is correct
34 Correct 443 ms 62160 KB Output is correct
35 Correct 42 ms 63032 KB Output is correct
36 Correct 71 ms 62928 KB Output is correct
37 Correct 280 ms 62144 KB Output is correct
38 Correct 296 ms 62160 KB Output is correct
39 Correct 53 ms 64140 KB Output is correct
40 Correct 67 ms 65036 KB Output is correct
41 Correct 696 ms 64136 KB Output is correct
42 Correct 315 ms 63940 KB Output is correct
43 Correct 769 ms 64136 KB Output is correct
44 Correct 702 ms 64140 KB Output is correct
45 Correct 739 ms 63900 KB Output is correct
46 Correct 537 ms 63952 KB Output is correct
47 Correct 47 ms 67012 KB Output is correct
48 Correct 78 ms 67008 KB Output is correct
49 Correct 1477 ms 67020 KB Output is correct
50 Correct 629 ms 67012 KB Output is correct
51 Correct 1446 ms 67860 KB Output is correct
52 Correct 1476 ms 67012 KB Output is correct
53 Correct 1453 ms 67024 KB Output is correct
54 Correct 1254 ms 67012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 53960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 58060 KB Output is correct
2 Correct 420 ms 62200 KB Output is correct
3 Correct 132 ms 62156 KB Output is correct
4 Correct 430 ms 62396 KB Output is correct
5 Correct 434 ms 62200 KB Output is correct
6 Correct 479 ms 62136 KB Output is correct
7 Correct 46 ms 62040 KB Output is correct
8 Correct 71 ms 61960 KB Output is correct
9 Correct 278 ms 62404 KB Output is correct
10 Correct 311 ms 62156 KB Output is correct
11 Correct 115 ms 58176 KB Output is correct
12 Correct 425 ms 62200 KB Output is correct
13 Correct 132 ms 62400 KB Output is correct
14 Correct 432 ms 62200 KB Output is correct
15 Correct 427 ms 62396 KB Output is correct
16 Correct 454 ms 62204 KB Output is correct
17 Correct 45 ms 62152 KB Output is correct
18 Correct 74 ms 62200 KB Output is correct
19 Correct 271 ms 62160 KB Output is correct
20 Correct 307 ms 62924 KB Output is correct
21 Correct 42 ms 63936 KB Output is correct
22 Correct 71 ms 64140 KB Output is correct
23 Correct 726 ms 64144 KB Output is correct
24 Correct 318 ms 63952 KB Output is correct
25 Correct 728 ms 64080 KB Output is correct
26 Correct 722 ms 63952 KB Output is correct
27 Correct 766 ms 63944 KB Output is correct
28 Correct 546 ms 63952 KB Output is correct
29 Correct 110 ms 58064 KB Output is correct
30 Correct 423 ms 62152 KB Output is correct
31 Correct 133 ms 62200 KB Output is correct
32 Correct 416 ms 62916 KB Output is correct
33 Correct 420 ms 61956 KB Output is correct
34 Correct 443 ms 62160 KB Output is correct
35 Correct 42 ms 63032 KB Output is correct
36 Correct 71 ms 62928 KB Output is correct
37 Correct 280 ms 62144 KB Output is correct
38 Correct 296 ms 62160 KB Output is correct
39 Correct 53 ms 64140 KB Output is correct
40 Correct 67 ms 65036 KB Output is correct
41 Correct 696 ms 64136 KB Output is correct
42 Correct 315 ms 63940 KB Output is correct
43 Correct 769 ms 64136 KB Output is correct
44 Correct 702 ms 64140 KB Output is correct
45 Correct 739 ms 63900 KB Output is correct
46 Correct 537 ms 63952 KB Output is correct
47 Correct 47 ms 67012 KB Output is correct
48 Correct 78 ms 67008 KB Output is correct
49 Correct 1477 ms 67020 KB Output is correct
50 Correct 629 ms 67012 KB Output is correct
51 Correct 1446 ms 67860 KB Output is correct
52 Correct 1476 ms 67012 KB Output is correct
53 Correct 1453 ms 67024 KB Output is correct
54 Correct 1254 ms 67012 KB Output is correct
55 Correct 105 ms 58172 KB Output is correct
56 Correct 410 ms 62156 KB Output is correct
57 Correct 131 ms 62356 KB Output is correct
58 Correct 425 ms 62160 KB Output is correct
59 Correct 422 ms 62400 KB Output is correct
60 Correct 455 ms 62148 KB Output is correct
61 Correct 42 ms 62160 KB Output is correct
62 Correct 67 ms 62156 KB Output is correct
63 Correct 269 ms 61972 KB Output is correct
64 Correct 299 ms 62200 KB Output is correct
65 Correct 44 ms 63948 KB Output is correct
66 Correct 67 ms 63940 KB Output is correct
67 Correct 702 ms 63940 KB Output is correct
68 Correct 314 ms 63940 KB Output is correct
69 Correct 703 ms 64136 KB Output is correct
70 Correct 707 ms 64144 KB Output is correct
71 Correct 737 ms 63940 KB Output is correct
72 Correct 541 ms 63948 KB Output is correct
73 Correct 45 ms 66824 KB Output is correct
74 Correct 76 ms 67860 KB Output is correct
75 Correct 1436 ms 67028 KB Output is correct
76 Correct 621 ms 67024 KB Output is correct
77 Correct 1495 ms 67008 KB Output is correct
78 Correct 1504 ms 67024 KB Output is correct
79 Correct 1451 ms 67068 KB Output is correct
80 Correct 1239 ms 67016 KB Output is correct
81 Correct 4336 ms 71820 KB Output is correct
82 Correct 2019 ms 71616 KB Output is correct
83 Correct 4477 ms 71820 KB Output is correct
84 Correct 4348 ms 71828 KB Output is correct
85 Correct 52 ms 72656 KB Output is correct
86 Correct 74 ms 71624 KB Output is correct
87 Correct 3946 ms 71816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 53960 KB Output isn't correct
2 Halted 0 ms 0 KB -