답안 #747876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747876 2023-05-25T02:36:20 Z JellyTheOctopus Snowball (JOI21_ho_t2) C++17
100 / 100
106 ms 15544 KB
#include <bits/stdc++.h>
using namespace std;

int N, Q;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N >> Q;
	vector<long long> pos(N+1);
	for (int i = 1; i <= N; i++) {
		cin >> pos[i];
	}
	vector<long long> space;
	vector<long long> L;
	vector<long long> R;
	vector<bool> get; // true is left
	space.push_back(0);
	L.push_back(0);
	R.push_back(0);
	get.push_back(0);
	long long farLeft = 0;
	long long farRight = 0;
	long long curPos = 0;
	long long spaceCovered = 0;
	for (int i = 1; i <= Q; i++) {
		long long add;
		cin >> add;
		if (add == 0) continue;
		curPos += add;
		if (i == 1) {
			spaceCovered += abs(curPos);
			space.push_back(spaceCovered);
			if (curPos > 0) {
				farRight = curPos;
				L.push_back(L.back()+curPos);
				R.push_back(R.back());
				get.push_back(1);
			}
			else {
				farLeft = curPos;
				L.push_back(L.back());
				R.push_back(R.back()-curPos);
				get.push_back(0);
			}
			continue;
		}
		if (curPos > farRight) {
			spaceCovered += abs(farRight-curPos);
			space.push_back(spaceCovered);
			L.push_back(L.back()+abs(farRight-curPos));
			R.push_back(R.back());
			get.push_back(1);
			farRight = curPos;
		}
		if (curPos < farLeft) {
			spaceCovered += abs(farLeft-curPos);
			space.push_back(spaceCovered);
			L.push_back(L.back());
			R.push_back(R.back()+abs(farLeft-curPos));
			get.push_back(0);
			farLeft = curPos;
		}
	}
	vector<long long> ans(N+1);
	for (int i = 1; i < N; i++) {
		long long diff = abs(pos[i+1]-pos[i]);
		auto it = lower_bound(space.begin(), space.end(), diff);
		if (it == space.end()) {
			ans[i] += L.back();
			ans[i+1] += R.back();
			continue;
		}
		int j = (it-space.begin());
		if (get[j]) {
			ans[i] += diff-R[j];
			ans[i+1] += R[j];
		}
		else {
			ans[i] += L[j];
			ans[i+1] += diff-L[j];
		}
	}
	ans[1] += abs(farLeft);
	ans[N] += abs(farRight);
	for (int i = 1; i <= N; i++) {
		cout << ans[i] << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 32 ms 7264 KB Output is correct
21 Correct 32 ms 7068 KB Output is correct
22 Correct 31 ms 6880 KB Output is correct
23 Correct 27 ms 6740 KB Output is correct
24 Correct 35 ms 7192 KB Output is correct
25 Correct 106 ms 13568 KB Output is correct
26 Correct 93 ms 13352 KB Output is correct
27 Correct 93 ms 12728 KB Output is correct
28 Correct 95 ms 12476 KB Output is correct
29 Correct 85 ms 10168 KB Output is correct
30 Correct 63 ms 7372 KB Output is correct
31 Correct 55 ms 6836 KB Output is correct
32 Correct 61 ms 6996 KB Output is correct
33 Correct 9 ms 1748 KB Output is correct
34 Correct 78 ms 9420 KB Output is correct
35 Correct 75 ms 9048 KB Output is correct
36 Correct 99 ms 13236 KB Output is correct
37 Correct 87 ms 11836 KB Output is correct
38 Correct 94 ms 12740 KB Output is correct
39 Correct 91 ms 12968 KB Output is correct
40 Correct 72 ms 12884 KB Output is correct
41 Correct 33 ms 7888 KB Output is correct
42 Correct 67 ms 6864 KB Output is correct
43 Correct 81 ms 15024 KB Output is correct
44 Correct 32 ms 7712 KB Output is correct
45 Correct 65 ms 12896 KB Output is correct
46 Correct 82 ms 15156 KB Output is correct
47 Correct 77 ms 12484 KB Output is correct
48 Correct 99 ms 15544 KB Output is correct