답안 #768212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768212 2023-06-27T17:10:07 Z NK_ Snowball (JOI21_ho_t2) C++17
100 / 100
269 ms 15404 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'

using ll = long long;
template<class T> using V = vector<T>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, Q; cin >> N >> Q;
	V<ll> A(N); for(auto& x : A) cin >> x;

	V<ll> MN(Q + 1, 0), MX(Q + 1, 0);
	ll cur = 0;
	for(int i = 1; i <= Q; i++) {
		ll x; cin >> x; cur += x;
		MN[i] = min(MN[i-1], cur);
		MX[i] = max(MX[i-1], cur);
		assert(MN[i] == MN[i-1] || MX[i] == MX[i-1]);
	}	

	V<ll> L(N), R(N);

	L[0] = MN.back() + A[0];
	R[N-1] = MX.back() + A[N-1];

	for(int i = 0; i < N-1; i++) {
		int lo = 0, hi = Q;
		while(lo < hi) {
			int mid = (lo + hi) / 2;

			ll l = MX[mid] + A[i], r = MN[mid] + A[i+1];
			if (l > r) hi = mid;
			else lo = mid + 1; 
		}

		int P = lo; assert(lo != 0);
		// cout << i << " " << P << endl;
		if (MX[P - 1] == MX[P]) {
			R[i] = MX[P] + A[i];
			L[i+1] = max(R[i], MN[P] + A[i+1]);
		} else {
			L[i+1] = MN[P] + A[i+1];
			R[i] = min(L[i+1], MX[P] + A[i]);
		}	
	}

	// for(int i = 0; i < N; i++) {
	// 	cout << L[i] << " | " << R[i] << endl;
	// }	

	for(int i = 0; i < N; i++) cout << R[i] - L[i] << endl;

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 3 ms 336 KB Output is correct
20 Correct 19 ms 5496 KB Output is correct
21 Correct 18 ms 5364 KB Output is correct
22 Correct 17 ms 5112 KB Output is correct
23 Correct 19 ms 4996 KB Output is correct
24 Correct 40 ms 5728 KB Output is correct
25 Correct 259 ms 13388 KB Output is correct
26 Correct 265 ms 13340 KB Output is correct
27 Correct 257 ms 12964 KB Output is correct
28 Correct 260 ms 13304 KB Output is correct
29 Correct 258 ms 12632 KB Output is correct
30 Correct 254 ms 12108 KB Output is correct
31 Correct 234 ms 11540 KB Output is correct
32 Correct 226 ms 11664 KB Output is correct
33 Correct 26 ms 1620 KB Output is correct
34 Correct 269 ms 13960 KB Output is correct
35 Correct 258 ms 13148 KB Output is correct
36 Correct 257 ms 13456 KB Output is correct
37 Correct 257 ms 13148 KB Output is correct
38 Correct 256 ms 13000 KB Output is correct
39 Correct 265 ms 13260 KB Output is correct
40 Correct 235 ms 13260 KB Output is correct
41 Correct 20 ms 6100 KB Output is correct
42 Correct 226 ms 11720 KB Output is correct
43 Correct 245 ms 14928 KB Output is correct
44 Correct 20 ms 5964 KB Output is correct
45 Correct 233 ms 13108 KB Output is correct
46 Correct 240 ms 15008 KB Output is correct
47 Correct 245 ms 15320 KB Output is correct
48 Correct 246 ms 15404 KB Output is correct