답안 #768213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768213 2023-06-27T17:11:00 Z NK_ Snowball (JOI21_ho_t2) C++17
100 / 100
269 ms 10004 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);
	}	

	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);
		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 << R[i] - L[i] << endl;

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 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 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 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 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 19 ms 3464 KB Output is correct
21 Correct 18 ms 3468 KB Output is correct
22 Correct 17 ms 3456 KB Output is correct
23 Correct 18 ms 3412 KB Output is correct
24 Correct 40 ms 4072 KB Output is correct
25 Correct 260 ms 9724 KB Output is correct
26 Correct 259 ms 9700 KB Output is correct
27 Correct 263 ms 9448 KB Output is correct
28 Correct 260 ms 9496 KB Output is correct
29 Correct 264 ms 9420 KB Output is correct
30 Correct 251 ms 8912 KB Output is correct
31 Correct 231 ms 8532 KB Output is correct
32 Correct 231 ms 8656 KB Output is correct
33 Correct 26 ms 1228 KB Output is correct
34 Correct 269 ms 9720 KB Output is correct
35 Correct 261 ms 9436 KB Output is correct
36 Correct 257 ms 9684 KB Output is correct
37 Correct 257 ms 9444 KB Output is correct
38 Correct 261 ms 9424 KB Output is correct
39 Correct 255 ms 9432 KB Output is correct
40 Correct 232 ms 9500 KB Output is correct
41 Correct 19 ms 3412 KB Output is correct
42 Correct 232 ms 8532 KB Output is correct
43 Correct 236 ms 9676 KB Output is correct
44 Correct 19 ms 3412 KB Output is correct
45 Correct 233 ms 9496 KB Output is correct
46 Correct 239 ms 9756 KB Output is correct
47 Correct 246 ms 10004 KB Output is correct
48 Correct 245 ms 9812 KB Output is correct