답안 #572879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572879 2022-06-05T12:25:52 Z awnqwq Uplifting Excursion (BOI22_vault) C++14
50 / 100
283 ms 2516 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define fi first
#define se second
#define mod 998244353
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}

#define N 310
#define M (N * N * 2)
int m, val[N * 2], s[M];
ll l, a[N * 2], b[N * 2];
pi dq[M];
void uup(int *s, int w, ll cnt, int d) {
	for (int i = 0; i < w; ++i) {
		int fr = 0, ba = 0;
		for (int j = i, k = 0; j < M; j += w, ++k) {
			int cur = s[j] - k * d;
			while (fr < ba && dq[ba - 1].fi <= cur) --ba;
			dq[ba++] = mp(cur, j);
			s[j] = k * d + dq[fr].fi;
			if (dq[fr].se + cnt * w == j) ++fr;
		}
	}
}
void udown(int *s, int w, ll cnt, int d) {
	for (int i = 0; i < w; ++i) {
		int fr = 0, ba = 0, k = M / w;
		if (w * k + i >= M) --k;
		for (int j = k * w + i; k >= 0; --k, j -= w) {
			int cur = s[j] + k * d;
			while (fr < ba && dq[ba - 1].fi <= cur) --ba;
			dq[ba++] = mp(cur, j);
			s[j] = dq[fr].fi - k * d;
			if (dq[fr].se - cnt * w == j) ++fr;
		}
	}
}
void solve() {
	scanf("%d%lld", &m, &l);
	ll sum = 0;
	for (int i = 0; i < m; ++i) {
		scanf("%lld", &a[m - i - 1]);
		val[m - i - 1] = m - i;
		l += a[m - i - 1] * (m - i);
		sum += a[m - i - 1];
	}
	for (int i = 0; i <= m; ++i) {
		scanf("%lld", &a[2 * m - i]);
		val[2 * m - i] = i;
	}
	sum += a[2 * m];
	for (int i = 2 * m - 1; i >= 0; --i) {
		ll take = min(l / val[i], a[i]);
		l -= take * val[i];
		sum += take * (i >= m ? 1 : -1);
		a[i] -= take;
		b[i] += take;
		if (a[i]) break;
	}
	memset(s, 0xc3, sizeof s);
	s[M / 2] = 0;
	for (int i = 0; i < 2 * m; ++i) {
		if (a[i]) uup(s, val[i], a[i], i < m ? -1 : 1);
		if (b[i]) udown(s, val[i], b[i], i < m ? 1 : -1);
	}
	if (l < 0 || l + M / 2 >= M || s[l + M / 2] < -M) printf("impossible\n");
	else printf("%lld\n", s[l + M / 2] + sum);
}
int main() {
	int T = 1;
	//scanf("%d", &T);
	while (T--) solve();
	return 0;
}

Compilation message

vault.cpp: In function 'void solve()':
vault.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d%lld", &m, &l);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
vault.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%lld", &a[m - i - 1]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
vault.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%lld", &a[2 * m - i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1748 KB Output is correct
2 Correct 4 ms 1492 KB Output is correct
3 Correct 3 ms 2516 KB Output is correct
4 Correct 11 ms 2452 KB Output is correct
5 Incorrect 93 ms 1728 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1748 KB Output is correct
2 Correct 4 ms 1492 KB Output is correct
3 Correct 3 ms 2516 KB Output is correct
4 Correct 11 ms 2452 KB Output is correct
5 Incorrect 93 ms 1728 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2516 KB Output is correct
2 Correct 27 ms 1108 KB Output is correct
3 Correct 10 ms 1108 KB Output is correct
4 Correct 34 ms 1128 KB Output is correct
5 Correct 30 ms 1108 KB Output is correct
6 Correct 33 ms 1124 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 17 ms 1144 KB Output is correct
10 Correct 21 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2516 KB Output is correct
2 Correct 27 ms 1108 KB Output is correct
3 Correct 10 ms 1108 KB Output is correct
4 Correct 34 ms 1128 KB Output is correct
5 Correct 30 ms 1108 KB Output is correct
6 Correct 33 ms 1124 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 17 ms 1144 KB Output is correct
10 Correct 21 ms 1132 KB Output is correct
11 Correct 5 ms 1820 KB Output is correct
12 Correct 4 ms 1492 KB Output is correct
13 Correct 3 ms 2516 KB Output is correct
14 Correct 11 ms 2472 KB Output is correct
15 Correct 28 ms 1108 KB Output is correct
16 Correct 10 ms 1108 KB Output is correct
17 Correct 30 ms 1108 KB Output is correct
18 Correct 30 ms 1108 KB Output is correct
19 Correct 29 ms 1144 KB Output is correct
20 Correct 4 ms 1124 KB Output is correct
21 Correct 7 ms 1120 KB Output is correct
22 Correct 18 ms 1136 KB Output is correct
23 Correct 21 ms 1132 KB Output is correct
24 Correct 57 ms 1108 KB Output is correct
25 Correct 22 ms 1264 KB Output is correct
26 Correct 59 ms 1124 KB Output is correct
27 Correct 61 ms 1108 KB Output is correct
28 Correct 60 ms 1184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2516 KB Output is correct
2 Correct 27 ms 1108 KB Output is correct
3 Correct 10 ms 1108 KB Output is correct
4 Correct 34 ms 1128 KB Output is correct
5 Correct 30 ms 1108 KB Output is correct
6 Correct 33 ms 1124 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 17 ms 1144 KB Output is correct
10 Correct 21 ms 1132 KB Output is correct
11 Correct 10 ms 2516 KB Output is correct
12 Correct 28 ms 1108 KB Output is correct
13 Correct 10 ms 1116 KB Output is correct
14 Correct 29 ms 1120 KB Output is correct
15 Correct 30 ms 1108 KB Output is correct
16 Correct 31 ms 1160 KB Output is correct
17 Correct 4 ms 1108 KB Output is correct
18 Correct 6 ms 1124 KB Output is correct
19 Correct 17 ms 1108 KB Output is correct
20 Correct 22 ms 1108 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 6 ms 1100 KB Output is correct
23 Correct 45 ms 1080 KB Output is correct
24 Correct 20 ms 980 KB Output is correct
25 Correct 43 ms 980 KB Output is correct
26 Correct 46 ms 980 KB Output is correct
27 Correct 50 ms 1088 KB Output is correct
28 Correct 34 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1748 KB Output is correct
2 Correct 4 ms 1492 KB Output is correct
3 Correct 3 ms 2516 KB Output is correct
4 Correct 11 ms 2452 KB Output is correct
5 Incorrect 93 ms 1728 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2516 KB Output is correct
2 Correct 27 ms 1108 KB Output is correct
3 Correct 10 ms 1108 KB Output is correct
4 Correct 34 ms 1128 KB Output is correct
5 Correct 30 ms 1108 KB Output is correct
6 Correct 33 ms 1124 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 17 ms 1144 KB Output is correct
10 Correct 21 ms 1132 KB Output is correct
11 Correct 10 ms 2516 KB Output is correct
12 Correct 28 ms 1108 KB Output is correct
13 Correct 10 ms 1116 KB Output is correct
14 Correct 29 ms 1120 KB Output is correct
15 Correct 30 ms 1108 KB Output is correct
16 Correct 31 ms 1160 KB Output is correct
17 Correct 4 ms 1108 KB Output is correct
18 Correct 6 ms 1124 KB Output is correct
19 Correct 17 ms 1108 KB Output is correct
20 Correct 22 ms 1108 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 6 ms 1100 KB Output is correct
23 Correct 45 ms 1080 KB Output is correct
24 Correct 20 ms 980 KB Output is correct
25 Correct 43 ms 980 KB Output is correct
26 Correct 46 ms 980 KB Output is correct
27 Correct 50 ms 1088 KB Output is correct
28 Correct 34 ms 980 KB Output is correct
29 Correct 9 ms 2516 KB Output is correct
30 Correct 28 ms 1108 KB Output is correct
31 Correct 10 ms 1044 KB Output is correct
32 Correct 33 ms 1108 KB Output is correct
33 Correct 28 ms 1108 KB Output is correct
34 Correct 29 ms 1140 KB Output is correct
35 Correct 4 ms 1124 KB Output is correct
36 Correct 6 ms 1108 KB Output is correct
37 Correct 17 ms 1140 KB Output is correct
38 Correct 23 ms 1132 KB Output is correct
39 Correct 3 ms 980 KB Output is correct
40 Correct 7 ms 1100 KB Output is correct
41 Correct 49 ms 1092 KB Output is correct
42 Correct 27 ms 980 KB Output is correct
43 Correct 50 ms 980 KB Output is correct
44 Correct 47 ms 980 KB Output is correct
45 Correct 48 ms 1200 KB Output is correct
46 Correct 33 ms 1080 KB Output is correct
47 Correct 3 ms 980 KB Output is correct
48 Correct 6 ms 1092 KB Output is correct
49 Correct 86 ms 980 KB Output is correct
50 Correct 37 ms 980 KB Output is correct
51 Correct 93 ms 980 KB Output is correct
52 Correct 94 ms 980 KB Output is correct
53 Correct 97 ms 1064 KB Output is correct
54 Correct 73 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1748 KB Output is correct
2 Correct 4 ms 1492 KB Output is correct
3 Correct 3 ms 2516 KB Output is correct
4 Correct 11 ms 2452 KB Output is correct
5 Incorrect 93 ms 1728 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2516 KB Output is correct
2 Correct 27 ms 1108 KB Output is correct
3 Correct 10 ms 1108 KB Output is correct
4 Correct 34 ms 1128 KB Output is correct
5 Correct 30 ms 1108 KB Output is correct
6 Correct 33 ms 1124 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 17 ms 1144 KB Output is correct
10 Correct 21 ms 1132 KB Output is correct
11 Correct 10 ms 2516 KB Output is correct
12 Correct 28 ms 1108 KB Output is correct
13 Correct 10 ms 1116 KB Output is correct
14 Correct 29 ms 1120 KB Output is correct
15 Correct 30 ms 1108 KB Output is correct
16 Correct 31 ms 1160 KB Output is correct
17 Correct 4 ms 1108 KB Output is correct
18 Correct 6 ms 1124 KB Output is correct
19 Correct 17 ms 1108 KB Output is correct
20 Correct 22 ms 1108 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 6 ms 1100 KB Output is correct
23 Correct 45 ms 1080 KB Output is correct
24 Correct 20 ms 980 KB Output is correct
25 Correct 43 ms 980 KB Output is correct
26 Correct 46 ms 980 KB Output is correct
27 Correct 50 ms 1088 KB Output is correct
28 Correct 34 ms 980 KB Output is correct
29 Correct 9 ms 2516 KB Output is correct
30 Correct 28 ms 1108 KB Output is correct
31 Correct 10 ms 1044 KB Output is correct
32 Correct 33 ms 1108 KB Output is correct
33 Correct 28 ms 1108 KB Output is correct
34 Correct 29 ms 1140 KB Output is correct
35 Correct 4 ms 1124 KB Output is correct
36 Correct 6 ms 1108 KB Output is correct
37 Correct 17 ms 1140 KB Output is correct
38 Correct 23 ms 1132 KB Output is correct
39 Correct 3 ms 980 KB Output is correct
40 Correct 7 ms 1100 KB Output is correct
41 Correct 49 ms 1092 KB Output is correct
42 Correct 27 ms 980 KB Output is correct
43 Correct 50 ms 980 KB Output is correct
44 Correct 47 ms 980 KB Output is correct
45 Correct 48 ms 1200 KB Output is correct
46 Correct 33 ms 1080 KB Output is correct
47 Correct 3 ms 980 KB Output is correct
48 Correct 6 ms 1092 KB Output is correct
49 Correct 86 ms 980 KB Output is correct
50 Correct 37 ms 980 KB Output is correct
51 Correct 93 ms 980 KB Output is correct
52 Correct 94 ms 980 KB Output is correct
53 Correct 97 ms 1064 KB Output is correct
54 Correct 73 ms 980 KB Output is correct
55 Correct 9 ms 2476 KB Output is correct
56 Correct 30 ms 1108 KB Output is correct
57 Correct 9 ms 1116 KB Output is correct
58 Correct 30 ms 1108 KB Output is correct
59 Correct 28 ms 1108 KB Output is correct
60 Correct 31 ms 1152 KB Output is correct
61 Correct 3 ms 1108 KB Output is correct
62 Correct 7 ms 1108 KB Output is correct
63 Correct 18 ms 1140 KB Output is correct
64 Correct 24 ms 1128 KB Output is correct
65 Correct 3 ms 1108 KB Output is correct
66 Correct 7 ms 1108 KB Output is correct
67 Correct 48 ms 1080 KB Output is correct
68 Correct 20 ms 1100 KB Output is correct
69 Correct 45 ms 1084 KB Output is correct
70 Correct 46 ms 1080 KB Output is correct
71 Correct 48 ms 1088 KB Output is correct
72 Correct 36 ms 1084 KB Output is correct
73 Correct 4 ms 980 KB Output is correct
74 Correct 6 ms 980 KB Output is correct
75 Correct 90 ms 1072 KB Output is correct
76 Correct 40 ms 980 KB Output is correct
77 Correct 89 ms 1016 KB Output is correct
78 Correct 90 ms 980 KB Output is correct
79 Correct 111 ms 1064 KB Output is correct
80 Correct 75 ms 1064 KB Output is correct
81 Correct 267 ms 980 KB Output is correct
82 Correct 127 ms 980 KB Output is correct
83 Correct 273 ms 1048 KB Output is correct
84 Correct 283 ms 1048 KB Output is correct
85 Correct 4 ms 980 KB Output is correct
86 Correct 7 ms 980 KB Output is correct
87 Correct 234 ms 1056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1748 KB Output is correct
2 Correct 4 ms 1492 KB Output is correct
3 Correct 3 ms 2516 KB Output is correct
4 Correct 11 ms 2452 KB Output is correct
5 Incorrect 93 ms 1728 KB Output isn't correct
6 Halted 0 ms 0 KB -