답안 #420411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
420411 2021-06-08T10:54:11 Z Berted Autobahn (COI21_autobahn) C++14
50 / 100
136 ms 7348 KB
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long
#define pii pair<int, int>
#define fst first
#define snd second

using namespace std;

const int INF = 1e9 + 7;

int N, K, X;
int cur[2];

vector<int> C;
vector<pii> op;
int val[300005];

ll ret = 0;

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0);
	cin >> N >> K >> X;

	C.push_back(-INF); C.push_back(INF);
	for (int i = 0; i < N; i++)
	{
		int L, t, R; cin >> L >> t >> R; L--;
		C.push_back(L); C.push_back(R);
		op.push_back({L, 1});
		op.push_back({R, -1});

		if (L + t < R)
		{
			C.push_back(L + t);
			op.push_back({L + t, 2});
			op.push_back({R, -2});
		}
	}

	sort(C.begin(), C.end());
	C.resize(unique(C.begin(), C.end()) - C.begin());
	sort(op.begin(), op.end());

	int j = 0;
	for (int i = 0; i < C.size(); i++)
	{
		for (; j < op.size() && op[j].fst <= C[i]; j++)
		{
			if (op[j].snd < 0) {cur[-op[j].snd - 1]--;}
			else {cur[op[j].snd - 1]++;}
		}
		if (cur[0] >= K) val[i] = cur[1];
		//cerr << i << ": " << C[i] << " " << cur[0] << " " << cur[1] << "\n";
	}

	j = 0; ll tmp = 0;
	for (int i = 1; i < C.size(); i++)
	{
		while (j < i - 1 && C[i] - C[j] > X)
		{
			ret = max(ret, (X - C[i - 1] + C[j]) * val[i - 1] + tmp);
			tmp -= (C[j + 1] - C[j]) * val[j]; j++;
		}
		if (C[i] - C[i - 1] <= X) tmp += (C[i] - C[i - 1]) * val[i - 1];
		else j++;
		if (j) ret = max(ret, tmp + (X - C[i] + C[j]) * val[j - 1]);
		else ret = max(ret, tmp);
	}

	cout << ret << "\n";

	return 0;
}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for (int i = 0; i < C.size(); i++)
      |                  ~~^~~~~~~~~~
autobahn.cpp:51:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for (; j < op.size() && op[j].fst <= C[i]; j++)
      |          ~~^~~~~~~~~~~
autobahn.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for (int i = 1; i < C.size(); i++)
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 113 ms 7260 KB Output is correct
22 Correct 136 ms 7348 KB Output is correct
23 Correct 112 ms 7264 KB Output is correct
24 Correct 111 ms 7320 KB Output is correct
25 Incorrect 113 ms 7316 KB Output isn't correct
26 Halted 0 ms 0 KB -