답안 #684879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684879 2023-01-22T18:11:45 Z sidon Autobahn (COI21_autobahn) C++17
100 / 100
236 ms 29824 KB
#include <bits/stdc++.h>
using namespace std;
#define int int64_t

const int INF = 2e9+1;

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, K, X; cin >> N >> K >> X;

	vector<array<int, 2>> a[2];
	vector<int> c;
	for(int i = 0; i < N; ++i) {
		int l, t, r; cin >> l >> t >> r;
		a[0].push_back({l, r});

		if(r - l + 1 > t)
			a[1].push_back({l + t, r});
	}

	for(auto &i : a) for(auto &j : i) for(int &k : j)
		for(int add : {-1, 0, 1}) c.push_back(k + add);

	sort(begin(c), end(c));

	c.erase(unique(begin(c), end(c)), end(c));
	int m = size(c);

	for(auto &i : a) for(auto &j : i) for(int &k : j)
		k = lower_bound(begin(c), end(c), k) - begin(c);

	int ans {};

	for(int __ : {0, 1}) {
		if(__) {

			for(int i : {0, 1}) for(auto &[l, r] : a[i]) {
				l = m - 1 - l, r = m - 1 - r;
				swap(l, r);
			}

			for(int &i : c) i = INF - i;
			reverse(begin(c), end(c));
		}

		int __sz = 2, add[__sz][m] {}, cur {};

		for(int k : {0, 1}) for(auto [i, j] : a[k]) {
			++add[k][i];
			--add[k][j+1];
		}

		for(int i = 1; i < m; ++i)
			for(int j : {0, 1})
				add[j][i] += add[j][i-1];

		for(int l = 0, r = 0; l < m; ++l) {

			while((r + 1) < m && (c[r + 1] - c[l]) < X) {
				if(add[0][r] >= K)
					cur += add[1][r] * (c[r + 1] - c[r]);
				++r;
			}

			int oh = cur;
			if(add[0][r] >= K) oh += add[1][r] * (X - (c[r] - c[l]));

			ans = max(ans, oh);

			if(l + 1 < m && add[0][l] >= K)
				cur -= add[1][l] * (c[l + 1] - c[l]);
		}
	}

	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 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 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 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 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 580 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 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 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 580 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 224 ms 29688 KB Output is correct
22 Correct 236 ms 29824 KB Output is correct
23 Correct 221 ms 29664 KB Output is correct
24 Correct 231 ms 29656 KB Output is correct
25 Correct 230 ms 29688 KB Output is correct
26 Correct 221 ms 29732 KB Output is correct
27 Correct 226 ms 29664 KB Output is correct
28 Correct 228 ms 29688 KB Output is correct
29 Correct 227 ms 29656 KB Output is correct