답안 #1112605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112605 2024-11-14T11:55:55 Z gelastropod Fire (BOI24_fire) C++14
61 / 100
350 ms 75160 KB
#include <climits>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define int long long

signed main(signed argc, char *argv[])
{
	int N, M, s, e;
	cin >> N >> M;
	vector<pair<int, int>> sorted;
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	map<int, int> vals;
	for (int i = 0; i < N; i++)
	{
		cin >> s >> e;
		if (s > e)
			e += M;
		vals[s] = max(vals[s], e);
	}
	map<int, int> endvals;
	while (!vals.empty())
	{
		sorted.push_back(*vals.begin());
		pq.push(*vals.begin());
		endvals[vals.begin()->second] = sorted.size() - 1;
		vals.erase(vals.begin());
	}
	N = sorted.size();
	vector<vector<int>> parent(31, vector<int>(N, -1));
	auto currvals = pq.top();
	int currmax = pq.top().second;
	int currind = 0;
	pq.pop();
	for (auto i : endvals)
	{
			while (currvals.first <= i.first)
			{
				if (currmax < currvals.second)
				{
					currmax = currvals.second;
					currind = N - pq.size() - 1;
				}
				if (pq.empty())
					currvals.first = LLONG_MAX;
				else
				{
					currvals = pq.top();
					pq.pop();
				}
			}
		if (currind == i.second)
			parent[0][i.second] = -1;
		else
			parent[0][i.second] = currind;
	}
	for (int i = 1; i < 31; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (parent[i - 1][j] == -1)
				parent[i][j] = -1;
			else
				parent[i][j] = parent[i - 1][parent[i - 1][j]];
		}
	}
	int ans = LLONG_MAX;
	for (int i = 0; i < N; i++)
	{
		int qq = i;
		int b = 0;
		int currans = 0;
		int a = sorted[i].first + M;
		for (int j = 30; j >= 0; j--)
		{
			int abc = parent[j][qq];
			if (abc != -1)
			{
				if (sorted[abc].second >= a)
					currans = b + (1 << j);
				else
					b += 1 << j, qq = abc;
			}
		}
		if (currans != 0)
			ans = min(ans, currans + 1);
	}
	if (ans == LLONG_MAX)
		cout << "-1\n";
	else
		cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 440 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 440 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 452 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 576 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 440 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 452 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 576 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 8 ms 2128 KB Output is correct
40 Correct 7 ms 2128 KB Output is correct
41 Correct 7 ms 2120 KB Output is correct
42 Correct 6 ms 2128 KB Output is correct
43 Correct 6 ms 1872 KB Output is correct
44 Correct 7 ms 2124 KB Output is correct
45 Correct 7 ms 2128 KB Output is correct
46 Correct 7 ms 2296 KB Output is correct
47 Correct 7 ms 2128 KB Output is correct
48 Correct 6 ms 2128 KB Output is correct
49 Correct 6 ms 2128 KB Output is correct
50 Correct 6 ms 2240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 7 ms 2300 KB Output is correct
16 Correct 6 ms 2044 KB Output is correct
17 Correct 7 ms 1724 KB Output is correct
18 Correct 10 ms 2128 KB Output is correct
19 Correct 7 ms 2128 KB Output is correct
20 Correct 36 ms 1172 KB Output is correct
21 Correct 350 ms 75160 KB Output is correct
22 Incorrect 313 ms 75076 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 6 ms 2140 KB Output is correct
13 Correct 6 ms 2296 KB Output is correct
14 Correct 6 ms 2128 KB Output is correct
15 Correct 44 ms 1040 KB Output is correct
16 Correct 289 ms 74148 KB Output is correct
17 Correct 312 ms 74916 KB Output is correct
18 Correct 309 ms 74908 KB Output is correct
19 Correct 301 ms 74892 KB Output is correct
20 Correct 296 ms 74084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 444 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 440 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 452 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 576 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 8 ms 2128 KB Output is correct
40 Correct 7 ms 2128 KB Output is correct
41 Correct 7 ms 2120 KB Output is correct
42 Correct 6 ms 2128 KB Output is correct
43 Correct 6 ms 1872 KB Output is correct
44 Correct 7 ms 2124 KB Output is correct
45 Correct 7 ms 2128 KB Output is correct
46 Correct 7 ms 2296 KB Output is correct
47 Correct 7 ms 2128 KB Output is correct
48 Correct 6 ms 2128 KB Output is correct
49 Correct 6 ms 2128 KB Output is correct
50 Correct 6 ms 2240 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 1 ms 336 KB Output is correct
55 Correct 1 ms 336 KB Output is correct
56 Correct 1 ms 336 KB Output is correct
57 Correct 1 ms 336 KB Output is correct
58 Correct 1 ms 336 KB Output is correct
59 Correct 1 ms 336 KB Output is correct
60 Correct 1 ms 336 KB Output is correct
61 Correct 1 ms 504 KB Output is correct
62 Correct 1 ms 336 KB Output is correct
63 Correct 1 ms 336 KB Output is correct
64 Correct 1 ms 336 KB Output is correct
65 Correct 7 ms 2300 KB Output is correct
66 Correct 6 ms 2044 KB Output is correct
67 Correct 7 ms 1724 KB Output is correct
68 Correct 10 ms 2128 KB Output is correct
69 Correct 7 ms 2128 KB Output is correct
70 Correct 36 ms 1172 KB Output is correct
71 Correct 350 ms 75160 KB Output is correct
72 Incorrect 313 ms 75076 KB Output isn't correct
73 Halted 0 ms 0 KB -