답안 #1028214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028214 2024-07-19T15:19:15 Z Issa Fire (BOI24_fire) C++17
100 / 100
69 ms 38968 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"

const int maxn = 1e6 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 20;
const int P = 31;

int n, m;
pii a[maxn];
int p[maxl][maxn];

void test(){
	cin >> n >> m;
	vector<pii> v;
	for(int i = 1; i <= n; i++){
		cin >> a[i].first >> a[i].second;
		if(a[i].second < a[i].first) a[i].second += m;
	}
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++){
		v.push_back({a[i].second, i});
	}
	sort(v.begin(), v.end());
	int j = 0, mx = 0;
	for(auto [x, i]: v){
		while(j < n && a[j+1].first <= x){
			j++; if(!mx || a[mx].second < a[j].second) mx = j;
		}
		p[0][i] = mx;
	}
	for(int k = 1; k < maxl; k++){
		for(int i = 1; i <= n; i++){
			p[k][i] = p[k-1][p[k-1][i]];
		}
	}
	int ans = inf;
	for(int i = 1; i <= n; i++){
		int j = i, cnt = 0;
		for(int k = maxl - 1; k >= 0; k--){
			if(a[p[k][j]].second - a[i].first < m){
				j = p[k][j]; cnt += (1<<k);
			}
		}
		j = p[0][j]; cnt++;
		if(a[j].second - a[i].first >= m){
			ans = min(ans, cnt + 1);
		}
	}
	if(ans == inf) ans = -1;
	cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; t = 1;
    while(t--) test();
    cout << ent;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 29020 KB Output is correct
2 Correct 3 ms 29020 KB Output is correct
3 Correct 2 ms 29020 KB Output is correct
4 Correct 3 ms 29020 KB Output is correct
5 Correct 2 ms 29020 KB Output is correct
6 Correct 3 ms 29020 KB Output is correct
7 Correct 3 ms 29020 KB Output is correct
8 Correct 3 ms 29020 KB Output is correct
9 Correct 3 ms 29020 KB Output is correct
10 Correct 2 ms 29020 KB Output is correct
11 Correct 3 ms 31064 KB Output is correct
12 Correct 2 ms 29160 KB Output is correct
13 Correct 3 ms 29016 KB Output is correct
14 Correct 3 ms 29016 KB Output is correct
15 Correct 3 ms 29020 KB Output is correct
16 Correct 3 ms 29016 KB Output is correct
17 Correct 3 ms 31068 KB Output is correct
18 Correct 3 ms 29020 KB Output is correct
19 Correct 3 ms 29020 KB Output is correct
20 Correct 3 ms 29020 KB Output is correct
21 Correct 3 ms 29020 KB Output is correct
22 Correct 3 ms 31068 KB Output is correct
23 Correct 2 ms 29148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 29020 KB Output is correct
2 Correct 3 ms 29020 KB Output is correct
3 Correct 2 ms 29020 KB Output is correct
4 Correct 3 ms 29020 KB Output is correct
5 Correct 2 ms 29020 KB Output is correct
6 Correct 3 ms 29020 KB Output is correct
7 Correct 3 ms 29020 KB Output is correct
8 Correct 3 ms 29020 KB Output is correct
9 Correct 3 ms 29020 KB Output is correct
10 Correct 2 ms 29020 KB Output is correct
11 Correct 3 ms 31064 KB Output is correct
12 Correct 2 ms 29160 KB Output is correct
13 Correct 3 ms 29016 KB Output is correct
14 Correct 3 ms 29016 KB Output is correct
15 Correct 3 ms 29020 KB Output is correct
16 Correct 3 ms 29016 KB Output is correct
17 Correct 3 ms 31068 KB Output is correct
18 Correct 3 ms 29020 KB Output is correct
19 Correct 3 ms 29020 KB Output is correct
20 Correct 3 ms 29020 KB Output is correct
21 Correct 3 ms 29020 KB Output is correct
22 Correct 3 ms 31068 KB Output is correct
23 Correct 2 ms 29148 KB Output is correct
24 Correct 3 ms 31320 KB Output is correct
25 Correct 3 ms 29020 KB Output is correct
26 Correct 3 ms 29020 KB Output is correct
27 Correct 3 ms 29020 KB Output is correct
28 Correct 3 ms 29020 KB Output is correct
29 Correct 2 ms 29020 KB Output is correct
30 Correct 3 ms 29092 KB Output is correct
31 Correct 3 ms 31068 KB Output is correct
32 Correct 3 ms 29020 KB Output is correct
33 Correct 3 ms 29020 KB Output is correct
34 Correct 3 ms 29020 KB Output is correct
35 Correct 3 ms 29020 KB Output is correct
36 Correct 3 ms 29020 KB Output is correct
37 Correct 3 ms 29016 KB Output is correct
38 Correct 3 ms 29020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 29020 KB Output is correct
2 Correct 3 ms 29020 KB Output is correct
3 Correct 2 ms 29020 KB Output is correct
4 Correct 3 ms 29020 KB Output is correct
5 Correct 2 ms 29020 KB Output is correct
6 Correct 3 ms 29020 KB Output is correct
7 Correct 3 ms 29020 KB Output is correct
8 Correct 3 ms 29020 KB Output is correct
9 Correct 3 ms 29020 KB Output is correct
10 Correct 2 ms 29020 KB Output is correct
11 Correct 3 ms 31064 KB Output is correct
12 Correct 2 ms 29160 KB Output is correct
13 Correct 3 ms 29016 KB Output is correct
14 Correct 3 ms 29016 KB Output is correct
15 Correct 3 ms 29020 KB Output is correct
16 Correct 3 ms 29016 KB Output is correct
17 Correct 3 ms 31068 KB Output is correct
18 Correct 3 ms 29020 KB Output is correct
19 Correct 3 ms 29020 KB Output is correct
20 Correct 3 ms 29020 KB Output is correct
21 Correct 3 ms 29020 KB Output is correct
22 Correct 3 ms 31068 KB Output is correct
23 Correct 2 ms 29148 KB Output is correct
24 Correct 3 ms 31320 KB Output is correct
25 Correct 3 ms 29020 KB Output is correct
26 Correct 3 ms 29020 KB Output is correct
27 Correct 3 ms 29020 KB Output is correct
28 Correct 3 ms 29020 KB Output is correct
29 Correct 2 ms 29020 KB Output is correct
30 Correct 3 ms 29092 KB Output is correct
31 Correct 3 ms 31068 KB Output is correct
32 Correct 3 ms 29020 KB Output is correct
33 Correct 3 ms 29020 KB Output is correct
34 Correct 3 ms 29020 KB Output is correct
35 Correct 3 ms 29020 KB Output is correct
36 Correct 3 ms 29020 KB Output is correct
37 Correct 3 ms 29016 KB Output is correct
38 Correct 3 ms 29020 KB Output is correct
39 Correct 4 ms 31324 KB Output is correct
40 Correct 4 ms 29308 KB Output is correct
41 Correct 4 ms 31336 KB Output is correct
42 Correct 4 ms 29276 KB Output is correct
43 Correct 5 ms 29276 KB Output is correct
44 Correct 4 ms 29276 KB Output is correct
45 Correct 4 ms 29276 KB Output is correct
46 Correct 4 ms 29272 KB Output is correct
47 Correct 4 ms 29396 KB Output is correct
48 Correct 4 ms 29276 KB Output is correct
49 Correct 3 ms 29276 KB Output is correct
50 Correct 4 ms 31324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 29020 KB Output is correct
2 Correct 3 ms 29020 KB Output is correct
3 Correct 3 ms 29020 KB Output is correct
4 Correct 3 ms 31184 KB Output is correct
5 Correct 3 ms 29192 KB Output is correct
6 Correct 3 ms 29020 KB Output is correct
7 Correct 2 ms 29164 KB Output is correct
8 Correct 2 ms 29020 KB Output is correct
9 Correct 3 ms 29020 KB Output is correct
10 Correct 3 ms 29020 KB Output is correct
11 Correct 3 ms 29020 KB Output is correct
12 Correct 3 ms 29020 KB Output is correct
13 Correct 3 ms 31068 KB Output is correct
14 Correct 3 ms 29020 KB Output is correct
15 Correct 4 ms 29276 KB Output is correct
16 Correct 5 ms 29276 KB Output is correct
17 Correct 4 ms 29276 KB Output is correct
18 Correct 4 ms 29276 KB Output is correct
19 Correct 4 ms 29316 KB Output is correct
20 Correct 49 ms 38856 KB Output is correct
21 Correct 62 ms 38856 KB Output is correct
22 Correct 64 ms 38856 KB Output is correct
23 Correct 69 ms 38724 KB Output is correct
24 Correct 61 ms 38856 KB Output is correct
25 Correct 66 ms 38812 KB Output is correct
26 Correct 61 ms 38848 KB Output is correct
27 Correct 57 ms 38860 KB Output is correct
28 Correct 64 ms 38856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 29020 KB Output is correct
2 Correct 3 ms 29020 KB Output is correct
3 Correct 3 ms 31068 KB Output is correct
4 Correct 3 ms 29020 KB Output is correct
5 Correct 3 ms 29020 KB Output is correct
6 Correct 3 ms 29020 KB Output is correct
7 Correct 3 ms 29020 KB Output is correct
8 Correct 3 ms 29020 KB Output is correct
9 Correct 3 ms 31068 KB Output is correct
10 Correct 3 ms 29020 KB Output is correct
11 Correct 3 ms 29020 KB Output is correct
12 Correct 5 ms 29276 KB Output is correct
13 Correct 4 ms 29276 KB Output is correct
14 Correct 4 ms 29276 KB Output is correct
15 Correct 37 ms 38732 KB Output is correct
16 Correct 54 ms 38860 KB Output is correct
17 Correct 65 ms 37832 KB Output is correct
18 Correct 60 ms 36296 KB Output is correct
19 Correct 57 ms 38968 KB Output is correct
20 Correct 54 ms 38964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 29020 KB Output is correct
2 Correct 3 ms 29020 KB Output is correct
3 Correct 2 ms 29020 KB Output is correct
4 Correct 3 ms 29020 KB Output is correct
5 Correct 2 ms 29020 KB Output is correct
6 Correct 3 ms 29020 KB Output is correct
7 Correct 3 ms 29020 KB Output is correct
8 Correct 3 ms 29020 KB Output is correct
9 Correct 3 ms 29020 KB Output is correct
10 Correct 2 ms 29020 KB Output is correct
11 Correct 3 ms 31064 KB Output is correct
12 Correct 2 ms 29160 KB Output is correct
13 Correct 3 ms 29016 KB Output is correct
14 Correct 3 ms 29016 KB Output is correct
15 Correct 3 ms 29020 KB Output is correct
16 Correct 3 ms 29016 KB Output is correct
17 Correct 3 ms 31068 KB Output is correct
18 Correct 3 ms 29020 KB Output is correct
19 Correct 3 ms 29020 KB Output is correct
20 Correct 3 ms 29020 KB Output is correct
21 Correct 3 ms 29020 KB Output is correct
22 Correct 3 ms 31068 KB Output is correct
23 Correct 2 ms 29148 KB Output is correct
24 Correct 3 ms 31320 KB Output is correct
25 Correct 3 ms 29020 KB Output is correct
26 Correct 3 ms 29020 KB Output is correct
27 Correct 3 ms 29020 KB Output is correct
28 Correct 3 ms 29020 KB Output is correct
29 Correct 2 ms 29020 KB Output is correct
30 Correct 3 ms 29092 KB Output is correct
31 Correct 3 ms 31068 KB Output is correct
32 Correct 3 ms 29020 KB Output is correct
33 Correct 3 ms 29020 KB Output is correct
34 Correct 3 ms 29020 KB Output is correct
35 Correct 3 ms 29020 KB Output is correct
36 Correct 3 ms 29020 KB Output is correct
37 Correct 3 ms 29016 KB Output is correct
38 Correct 3 ms 29020 KB Output is correct
39 Correct 4 ms 31324 KB Output is correct
40 Correct 4 ms 29308 KB Output is correct
41 Correct 4 ms 31336 KB Output is correct
42 Correct 4 ms 29276 KB Output is correct
43 Correct 5 ms 29276 KB Output is correct
44 Correct 4 ms 29276 KB Output is correct
45 Correct 4 ms 29276 KB Output is correct
46 Correct 4 ms 29272 KB Output is correct
47 Correct 4 ms 29396 KB Output is correct
48 Correct 4 ms 29276 KB Output is correct
49 Correct 3 ms 29276 KB Output is correct
50 Correct 4 ms 31324 KB Output is correct
51 Correct 3 ms 29020 KB Output is correct
52 Correct 3 ms 29020 KB Output is correct
53 Correct 3 ms 29020 KB Output is correct
54 Correct 3 ms 31184 KB Output is correct
55 Correct 3 ms 29192 KB Output is correct
56 Correct 3 ms 29020 KB Output is correct
57 Correct 2 ms 29164 KB Output is correct
58 Correct 2 ms 29020 KB Output is correct
59 Correct 3 ms 29020 KB Output is correct
60 Correct 3 ms 29020 KB Output is correct
61 Correct 3 ms 29020 KB Output is correct
62 Correct 3 ms 29020 KB Output is correct
63 Correct 3 ms 31068 KB Output is correct
64 Correct 3 ms 29020 KB Output is correct
65 Correct 4 ms 29276 KB Output is correct
66 Correct 5 ms 29276 KB Output is correct
67 Correct 4 ms 29276 KB Output is correct
68 Correct 4 ms 29276 KB Output is correct
69 Correct 4 ms 29316 KB Output is correct
70 Correct 49 ms 38856 KB Output is correct
71 Correct 62 ms 38856 KB Output is correct
72 Correct 64 ms 38856 KB Output is correct
73 Correct 69 ms 38724 KB Output is correct
74 Correct 61 ms 38856 KB Output is correct
75 Correct 66 ms 38812 KB Output is correct
76 Correct 61 ms 38848 KB Output is correct
77 Correct 57 ms 38860 KB Output is correct
78 Correct 64 ms 38856 KB Output is correct
79 Correct 3 ms 29020 KB Output is correct
80 Correct 3 ms 29020 KB Output is correct
81 Correct 3 ms 31068 KB Output is correct
82 Correct 3 ms 29020 KB Output is correct
83 Correct 3 ms 29020 KB Output is correct
84 Correct 3 ms 29020 KB Output is correct
85 Correct 3 ms 29020 KB Output is correct
86 Correct 3 ms 29020 KB Output is correct
87 Correct 3 ms 31068 KB Output is correct
88 Correct 3 ms 29020 KB Output is correct
89 Correct 3 ms 29020 KB Output is correct
90 Correct 5 ms 29276 KB Output is correct
91 Correct 4 ms 29276 KB Output is correct
92 Correct 4 ms 29276 KB Output is correct
93 Correct 37 ms 38732 KB Output is correct
94 Correct 54 ms 38860 KB Output is correct
95 Correct 65 ms 37832 KB Output is correct
96 Correct 60 ms 36296 KB Output is correct
97 Correct 57 ms 38968 KB Output is correct
98 Correct 54 ms 38964 KB Output is correct
99 Correct 63 ms 38860 KB Output is correct
100 Correct 69 ms 38860 KB Output is correct
101 Correct 60 ms 38856 KB Output is correct
102 Correct 63 ms 38964 KB Output is correct
103 Correct 56 ms 38720 KB Output is correct
104 Correct 60 ms 38856 KB Output is correct
105 Correct 40 ms 38860 KB Output is correct