# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1065984 |
2024-08-19T13:52:12 Z |
Boomyday |
Fire (BOI24_fire) |
C++17 |
|
1408 ms |
87260 KB |
//
// Created by adavy on 8/19/2024.
//
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
#define f first
#define s second
int main(){
ll N,M; cin >> N >> M;
ll B = 25;
set<ll> coords;
vector<ll> s(N),e(N);
for(int i=0;i<N;++i) {
cin >> s[i] >> e[i];
coords.insert(s[i]);
coords.insert(e[i]);
}
vector<ll> coords_v(coords.begin(),coords.end());
map<ll,ll> coords_ind;
for(int i=0;i<coords_v.size();++i){
coords_ind[coords_v[i]] = i;
}
for(int i=0;i<N;++i){
s[i] = coords_ind[s[i]];
e[i] = coords_ind[e[i]];
}
M = coords.size();
for(int i=0;i<N;++i){
if (e[i] < s[i]){
e[i] += M;
}
}
// output starts and ends
vector<vector<int>> best_next(N, vector<int>(B));
vector<pair<pair<int,int>,int>> sweep; // time, {0 open 1 close}, number
for(int i=0;i<N;++i){
sweep.push_back({{s[i],0},i});
sweep.push_back({{e[i],1},i});
}
sort(sweep.begin(),sweep.end());
multiset<pair<int,int>,greater<pair<int,int>>> open; // end, number
for(auto&[state,ind]:sweep){
if (state.s == 0){
open.insert({e[ind],ind});
}
else {
best_next[ind][0] = open.begin()->s;
open.erase({e[ind],ind});
}
}
for(int j=1;j<B;++j){
for(int i=0;i<N;++i){
best_next[i][j] = best_next[best_next[i][j-1]][j-1];
}
}
ll lo = 0, hi = 3*N;
while (lo<hi){
bool is_good = false;
ll mid = (lo+hi)/2;
for(int i=0;i<N;++i){
ll cur = i;
for(int j=0;j<B;++j){
if (mid & (1<<j)){
cur = best_next[cur][j];
}
}
if (e[cur] - s[i] >= M){
//cout << i << " " << cur << " " << mid << endl;
is_good = true;
break;
}
}
if (is_good){
hi = mid;
}
else {
lo = mid+1;
}
}
if (hi == 3*N){
cout << -1 << endl;
}
else {
cout << hi+1 << endl;
}
// output best nexts
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i=0;i<coords_v.size();++i){
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
440 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
440 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
440 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
9 ms |
2652 KB |
Output is correct |
40 |
Correct |
11 ms |
2652 KB |
Output is correct |
41 |
Correct |
9 ms |
2688 KB |
Output is correct |
42 |
Correct |
8 ms |
2072 KB |
Output is correct |
43 |
Correct |
7 ms |
1884 KB |
Output is correct |
44 |
Correct |
11 ms |
1956 KB |
Output is correct |
45 |
Correct |
9 ms |
2140 KB |
Output is correct |
46 |
Correct |
10 ms |
2140 KB |
Output is correct |
47 |
Correct |
9 ms |
2700 KB |
Output is correct |
48 |
Correct |
9 ms |
2656 KB |
Output is correct |
49 |
Correct |
7 ms |
2652 KB |
Output is correct |
50 |
Correct |
8 ms |
2076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
9 ms |
2652 KB |
Output is correct |
16 |
Correct |
8 ms |
2072 KB |
Output is correct |
17 |
Correct |
7 ms |
1884 KB |
Output is correct |
18 |
Correct |
10 ms |
2116 KB |
Output is correct |
19 |
Correct |
9 ms |
2652 KB |
Output is correct |
20 |
Correct |
151 ms |
45004 KB |
Output is correct |
21 |
Correct |
812 ms |
87092 KB |
Output is correct |
22 |
Correct |
699 ms |
87232 KB |
Output is correct |
23 |
Correct |
803 ms |
62740 KB |
Output is correct |
24 |
Correct |
1240 ms |
87236 KB |
Output is correct |
25 |
Correct |
470 ms |
58552 KB |
Output is correct |
26 |
Correct |
728 ms |
63688 KB |
Output is correct |
27 |
Correct |
927 ms |
63684 KB |
Output is correct |
28 |
Correct |
1080 ms |
86072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
15 ms |
2544 KB |
Output is correct |
13 |
Correct |
9 ms |
2072 KB |
Output is correct |
14 |
Correct |
8 ms |
2076 KB |
Output is correct |
15 |
Correct |
151 ms |
44868 KB |
Output is correct |
16 |
Correct |
1065 ms |
62656 KB |
Output is correct |
17 |
Correct |
817 ms |
87260 KB |
Output is correct |
18 |
Correct |
728 ms |
87044 KB |
Output is correct |
19 |
Correct |
1218 ms |
87104 KB |
Output is correct |
20 |
Correct |
977 ms |
62656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
444 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
440 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
9 ms |
2652 KB |
Output is correct |
40 |
Correct |
11 ms |
2652 KB |
Output is correct |
41 |
Correct |
9 ms |
2688 KB |
Output is correct |
42 |
Correct |
8 ms |
2072 KB |
Output is correct |
43 |
Correct |
7 ms |
1884 KB |
Output is correct |
44 |
Correct |
11 ms |
1956 KB |
Output is correct |
45 |
Correct |
9 ms |
2140 KB |
Output is correct |
46 |
Correct |
10 ms |
2140 KB |
Output is correct |
47 |
Correct |
9 ms |
2700 KB |
Output is correct |
48 |
Correct |
9 ms |
2656 KB |
Output is correct |
49 |
Correct |
7 ms |
2652 KB |
Output is correct |
50 |
Correct |
8 ms |
2076 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
436 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
348 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
9 ms |
2652 KB |
Output is correct |
66 |
Correct |
8 ms |
2072 KB |
Output is correct |
67 |
Correct |
7 ms |
1884 KB |
Output is correct |
68 |
Correct |
10 ms |
2116 KB |
Output is correct |
69 |
Correct |
9 ms |
2652 KB |
Output is correct |
70 |
Correct |
151 ms |
45004 KB |
Output is correct |
71 |
Correct |
812 ms |
87092 KB |
Output is correct |
72 |
Correct |
699 ms |
87232 KB |
Output is correct |
73 |
Correct |
803 ms |
62740 KB |
Output is correct |
74 |
Correct |
1240 ms |
87236 KB |
Output is correct |
75 |
Correct |
470 ms |
58552 KB |
Output is correct |
76 |
Correct |
728 ms |
63688 KB |
Output is correct |
77 |
Correct |
927 ms |
63684 KB |
Output is correct |
78 |
Correct |
1080 ms |
86072 KB |
Output is correct |
79 |
Correct |
0 ms |
344 KB |
Output is correct |
80 |
Correct |
0 ms |
348 KB |
Output is correct |
81 |
Correct |
1 ms |
348 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
1 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
0 ms |
348 KB |
Output is correct |
86 |
Correct |
1 ms |
348 KB |
Output is correct |
87 |
Correct |
1 ms |
348 KB |
Output is correct |
88 |
Correct |
1 ms |
348 KB |
Output is correct |
89 |
Correct |
1 ms |
600 KB |
Output is correct |
90 |
Correct |
15 ms |
2544 KB |
Output is correct |
91 |
Correct |
9 ms |
2072 KB |
Output is correct |
92 |
Correct |
8 ms |
2076 KB |
Output is correct |
93 |
Correct |
151 ms |
44868 KB |
Output is correct |
94 |
Correct |
1065 ms |
62656 KB |
Output is correct |
95 |
Correct |
817 ms |
87260 KB |
Output is correct |
96 |
Correct |
728 ms |
87044 KB |
Output is correct |
97 |
Correct |
1218 ms |
87104 KB |
Output is correct |
98 |
Correct |
977 ms |
62656 KB |
Output is correct |
99 |
Correct |
1343 ms |
87260 KB |
Output is correct |
100 |
Correct |
801 ms |
87236 KB |
Output is correct |
101 |
Correct |
1272 ms |
87236 KB |
Output is correct |
102 |
Correct |
1245 ms |
87236 KB |
Output is correct |
103 |
Correct |
1408 ms |
63688 KB |
Output is correct |
104 |
Correct |
869 ms |
84920 KB |
Output is correct |
105 |
Correct |
384 ms |
85820 KB |
Output is correct |