답안 #913929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913929 2024-01-20T14:00:57 Z goodspeed0208 Snowball (JOI21_ho_t2) C++14
100 / 100
92 ms 16980 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#define int long long 
using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector<int>v(n), w(q+5, 0), left(q+5, 0), right(q+5, 0);
	vector<int>ansleft(n), ansright(n);
	for (auto &i : v) cin >> i;
	for (int i = 1 ; i <= q ; i++) {
		cin >> w[i];
		w[i] = w[i-1] + w[i];
		right[i] = max(right[i-1], w[i]);
		left[i] = max(left[i-1], -w[i]);
	//	cout << left[i] << " " << right[i] << "\n";
	}
	ansleft[0] = left[q];
	ansright[n-1] = right[q];
	for (int i = 0 ; i < n-1 ; i++) {
		int l = 0, r = q+1, mid;
		while (l + 1 < r) {
			mid = (l + r) / 2;
			if (left[mid] + right[mid] <= v[i+1] - v[i]) {
				ansright[i] = right[mid];
				ansleft[i+1] = left[mid];
				l = mid;
			} else {
				r = mid;
			}
		}
		if (l == q) continue;
		if (left[r] != left[r-1]) ansleft[i+1] = v[i+1] - v[i] - ansright[i];
		else ansright[i] = v[i+1] - v[i] - ansleft[i+1];
	}
	for (int i = 0 ; i < n ; i++) {
		cout << ansleft[i] + ansright[i] << "\n";
	}
}













# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 576 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 576 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 21 ms 7248 KB Output is correct
21 Correct 24 ms 7004 KB Output is correct
22 Correct 19 ms 6692 KB Output is correct
23 Correct 19 ms 6736 KB Output is correct
24 Correct 27 ms 7260 KB Output is correct
25 Correct 81 ms 14944 KB Output is correct
26 Correct 78 ms 15056 KB Output is correct
27 Correct 79 ms 14676 KB Output is correct
28 Correct 83 ms 14676 KB Output is correct
29 Correct 76 ms 14504 KB Output is correct
30 Correct 81 ms 13776 KB Output is correct
31 Correct 58 ms 13180 KB Output is correct
32 Correct 48 ms 13392 KB Output is correct
33 Correct 8 ms 1880 KB Output is correct
34 Correct 82 ms 15444 KB Output is correct
35 Correct 92 ms 14804 KB Output is correct
36 Correct 80 ms 15096 KB Output is correct
37 Correct 78 ms 14796 KB Output is correct
38 Correct 85 ms 14644 KB Output is correct
39 Correct 77 ms 14836 KB Output is correct
40 Correct 56 ms 14820 KB Output is correct
41 Correct 22 ms 7772 KB Output is correct
42 Correct 49 ms 13140 KB Output is correct
43 Correct 58 ms 16468 KB Output is correct
44 Correct 22 ms 7768 KB Output is correct
45 Correct 53 ms 14696 KB Output is correct
46 Correct 65 ms 16612 KB Output is correct
47 Correct 74 ms 16980 KB Output is correct
48 Correct 64 ms 16980 KB Output is correct