답안 #391482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391482 2021-04-18T21:21:01 Z ritul_kr_singh Snowball (JOI21_ho_t2) C++17
100 / 100
120 ms 16856 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'

signed main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, q; cin >> n >> q;
	int x[n]; for(int &i : x) cin >> i;
	int w[q]; for(int &i : w) cin >> i;

	int a[q], b[q];
	a[0] = max(w[0], 0LL);
	b[0] = min(w[0], 0LL);

	for(int i=1; i<q; ++i){
		w[i] += w[i-1];
		a[i] = max(a[i-1], w[i]);
		b[i] = min(b[i-1], w[i]);
	}

	for(int &i : b) i = -i;

	int l[n], r[n];
	fill(l, l+n, 0LL);
	fill(r, r+n, 0LL);

	for(int i=0; i+1<n; ++i){
		int diff = x[i+1] - x[i];
		if(a[0] + b[0] >= diff){
			r[i] = min(diff, a[0]);
			l[i+1] = min(diff, b[0]);
			continue;
		}
		int low = 0, high = q-1;
		while(low < high){
			int mid = (low + high) / 2;
			if(a[mid+1] + b[mid+1] < diff) low = mid+1;
			else high = mid;
		}
		int mx = low;
		r[i] = a[mx];
		l[i+1] = b[mx];
		++mx;
		if(mx < q){
			l[i+1] = min(diff - a[mx-1], b[mx]);
			r[i] = min(diff - b[mx-1], a[mx]);
		}
	}
	l[0] = b[q-1];
	r[n-1] = a[q-1];
	for(int i=0; i<n; ++i) cout << l[i] + r[i] nl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 456 KB Output is correct
16 Correct 2 ms 456 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 456 KB Output is correct
16 Correct 2 ms 456 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 40 ms 7108 KB Output is correct
21 Correct 32 ms 6816 KB Output is correct
22 Correct 30 ms 6752 KB Output is correct
23 Correct 28 ms 6544 KB Output is correct
24 Correct 35 ms 7256 KB Output is correct
25 Correct 117 ms 15028 KB Output is correct
26 Correct 118 ms 14880 KB Output is correct
27 Correct 120 ms 14532 KB Output is correct
28 Correct 113 ms 14744 KB Output is correct
29 Correct 112 ms 14200 KB Output is correct
30 Correct 107 ms 13624 KB Output is correct
31 Correct 88 ms 12988 KB Output is correct
32 Correct 83 ms 13124 KB Output is correct
33 Correct 10 ms 1736 KB Output is correct
34 Correct 119 ms 15332 KB Output is correct
35 Correct 114 ms 14660 KB Output is correct
36 Correct 115 ms 14916 KB Output is correct
37 Correct 120 ms 14636 KB Output is correct
38 Correct 114 ms 14508 KB Output is correct
39 Correct 111 ms 14808 KB Output is correct
40 Correct 94 ms 14884 KB Output is correct
41 Correct 34 ms 7612 KB Output is correct
42 Correct 80 ms 13212 KB Output is correct
43 Correct 87 ms 16488 KB Output is correct
44 Correct 35 ms 7492 KB Output is correct
45 Correct 89 ms 14744 KB Output is correct
46 Correct 89 ms 16532 KB Output is correct
47 Correct 91 ms 16828 KB Output is correct
48 Correct 90 ms 16856 KB Output is correct