답안 #757618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757618 2023-06-13T12:40:42 Z stefdasca Snowball (JOI21_ho_t2) C++14
100 / 100
133 ms 8296 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, q;
	cin >> n >> q;
	
	vector<long long> v(n+1);
	for(int i = 1; i <= n; i++)
		cin >> v[i];
	
	vector<long long> minq(q+1), maxq(q+1);
	long long sum = 0;

	for(int i = 1; i <= q; i++)
	{
		long long x;
		cin >> x;
		sum += x;
		minq[i] = min(minq[i-1], sum);
		maxq[i] = max(maxq[i-1], sum);
	}
	
	vector<long long> ans(n+1);
	for(int i = 1; i < n; i++)
	{
		int st = 1;
		int dr = q;
		int poz = 0;
		while(st <= dr)
		{
			int mid = (st + dr) / 2;
			if(abs(minq[mid]) + abs(maxq[mid]) < v[i+1] - v[i])
			{
				poz = mid;
				st = mid + 1;
			}
			else
				dr = mid - 1;
		}
		
		ans[i] += maxq[poz];
		ans[i+1] += abs(minq[poz]);
		
		if(poz != q && maxq[poz+1] > maxq[poz])
			ans[i] += (v[i+1] - v[i]) - (abs(minq[poz]) + abs(maxq[poz]));
		
		if(poz != q && minq[poz+1] < minq[poz])
			ans[i+1] += (v[i+1] - v[i]) - (abs(minq[poz]) + abs(maxq[poz]));
	}
	
	ans[1] += abs(minq[q]);
	ans[n] += abs(maxq[q]);
	
	for(int i = 1; i <= n; i++)
		cout << ans[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 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 340 KB Output is correct
5 Correct 2 ms 312 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 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 340 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 340 KB Output is correct
5 Correct 2 ms 312 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 25 ms 3412 KB Output is correct
21 Correct 24 ms 3412 KB Output is correct
22 Correct 23 ms 3412 KB Output is correct
23 Correct 21 ms 3488 KB Output is correct
24 Correct 31 ms 3884 KB Output is correct
25 Correct 112 ms 8152 KB Output is correct
26 Correct 107 ms 8088 KB Output is correct
27 Correct 113 ms 7900 KB Output is correct
28 Correct 122 ms 7888 KB Output is correct
29 Correct 92 ms 7716 KB Output is correct
30 Correct 85 ms 7344 KB Output is correct
31 Correct 78 ms 6872 KB Output is correct
32 Correct 54 ms 6968 KB Output is correct
33 Correct 9 ms 1104 KB Output is correct
34 Correct 98 ms 8160 KB Output is correct
35 Correct 96 ms 7904 KB Output is correct
36 Correct 95 ms 8140 KB Output is correct
37 Correct 94 ms 7856 KB Output is correct
38 Correct 133 ms 7884 KB Output is correct
39 Correct 90 ms 7940 KB Output is correct
40 Correct 65 ms 7956 KB Output is correct
41 Correct 28 ms 3412 KB Output is correct
42 Correct 71 ms 6964 KB Output is correct
43 Correct 75 ms 8168 KB Output is correct
44 Correct 28 ms 3456 KB Output is correct
45 Correct 67 ms 7964 KB Output is correct
46 Correct 98 ms 8268 KB Output is correct
47 Correct 79 ms 8296 KB Output is correct
48 Correct 76 ms 8268 KB Output is correct