# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1095803 |
2024-10-03T07:59:31 Z |
SalihSahin |
Fire (BOI24_fire) |
C++14 |
|
1463 ms |
181180 KB |
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
const int K = 20;
const int mod = 1e9 + 7;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, m;
cin>>n>>m;
vector<pair<int, int> > a(n);
set<int> st;
for(int i = 0; i < n; i++){
cin>>a[i].first>>a[i].second;
st.insert(a[i].first);
st.insert(a[i].second);
st.insert(a[i].first + m);
st.insert(a[i].second + m);
}
map<int, int> pos;
int here = 0;
vector<int> vals;
vals.pb(0);
for(auto itr: st){
pos[itr] = ++here;
vals.pb(itr);
}
vector<int> upd(here + 1);
for(int i = 0; i < n; i++){
int f = a[i].first, s = a[i].second;
if(f > s){
upd[pos[f]] = max(upd[pos[f]], s + m);
}
else{
upd[pos[f]] = max(upd[pos[f]], s);
upd[pos[f + m]] = max(upd[pos[f]], s + m);
}
}
vector<vector<int> > lift(here + 1, vector<int>(K));
int val = 0;
for(auto itr: st){
val = max(val, upd[pos[itr]]);
lift[pos[itr]][0] = pos[val];
}
for(int i = 1; i < K; i++){
for(int j = 1; j <= here; j++){
lift[j][i] = lift[lift[j][i-1]][i-1];
}
}
int ans = n + 23;
for(int st = 0; st < n; st++){
int f = a[st].first;
int cnt = 0;
bool ok = 1;
int r = pos[f];
for(int bt = K-1; bt >= 0; bt--){
if(vals[lift[r][bt]] < m + f){
cnt += (1 << bt);
r = lift[r][bt];
}
}
if(vals[lift[r][0]] >= m + f) ans = min(ans, cnt + 1);
}
if(ans == n + 23) cout<<-1<<endl;
else cout<<ans<<endl;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:61:14: warning: unused variable 'ok' [-Wunused-variable]
61 | bool ok = 1;
| ^~
# |
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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
344 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 |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
344 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 |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
412 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 |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
720 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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
344 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 |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
412 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 |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
720 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
15 ms |
4896 KB |
Output is correct |
40 |
Correct |
16 ms |
4700 KB |
Output is correct |
41 |
Correct |
17 ms |
4832 KB |
Output is correct |
42 |
Correct |
9 ms |
2500 KB |
Output is correct |
43 |
Correct |
8 ms |
2140 KB |
Output is correct |
44 |
Correct |
9 ms |
2700 KB |
Output is correct |
45 |
Correct |
9 ms |
2652 KB |
Output is correct |
46 |
Correct |
10 ms |
2904 KB |
Output is correct |
47 |
Correct |
15 ms |
4700 KB |
Output is correct |
48 |
Correct |
14 ms |
4744 KB |
Output is correct |
49 |
Correct |
12 ms |
4696 KB |
Output is correct |
50 |
Correct |
9 ms |
2652 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
15 ms |
4700 KB |
Output is correct |
16 |
Correct |
9 ms |
2712 KB |
Output is correct |
17 |
Correct |
8 ms |
2140 KB |
Output is correct |
18 |
Correct |
9 ms |
2652 KB |
Output is correct |
19 |
Correct |
14 ms |
4700 KB |
Output is correct |
20 |
Correct |
25 ms |
1880 KB |
Output is correct |
21 |
Correct |
1326 ms |
177372 KB |
Output is correct |
22 |
Correct |
1309 ms |
181172 KB |
Output is correct |
23 |
Correct |
891 ms |
92612 KB |
Output is correct |
24 |
Correct |
1385 ms |
181180 KB |
Output is correct |
25 |
Correct |
648 ms |
75204 KB |
Output is correct |
26 |
Correct |
782 ms |
93376 KB |
Output is correct |
27 |
Correct |
819 ms |
93748 KB |
Output is correct |
28 |
Correct |
1168 ms |
176800 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
15 ms |
4860 KB |
Output is correct |
13 |
Correct |
9 ms |
2648 KB |
Output is correct |
14 |
Correct |
9 ms |
2704 KB |
Output is correct |
15 |
Correct |
25 ms |
1884 KB |
Output is correct |
16 |
Correct |
852 ms |
89536 KB |
Output is correct |
17 |
Correct |
1356 ms |
180988 KB |
Output is correct |
18 |
Correct |
1403 ms |
181176 KB |
Output is correct |
19 |
Correct |
1337 ms |
181180 KB |
Output is correct |
20 |
Correct |
1036 ms |
92608 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 |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
344 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 |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
412 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 |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
720 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
15 ms |
4896 KB |
Output is correct |
40 |
Correct |
16 ms |
4700 KB |
Output is correct |
41 |
Correct |
17 ms |
4832 KB |
Output is correct |
42 |
Correct |
9 ms |
2500 KB |
Output is correct |
43 |
Correct |
8 ms |
2140 KB |
Output is correct |
44 |
Correct |
9 ms |
2700 KB |
Output is correct |
45 |
Correct |
9 ms |
2652 KB |
Output is correct |
46 |
Correct |
10 ms |
2904 KB |
Output is correct |
47 |
Correct |
15 ms |
4700 KB |
Output is correct |
48 |
Correct |
14 ms |
4744 KB |
Output is correct |
49 |
Correct |
12 ms |
4696 KB |
Output is correct |
50 |
Correct |
9 ms |
2652 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
344 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 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 |
604 KB |
Output is correct |
61 |
Correct |
1 ms |
348 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
604 KB |
Output is correct |
65 |
Correct |
15 ms |
4700 KB |
Output is correct |
66 |
Correct |
9 ms |
2712 KB |
Output is correct |
67 |
Correct |
8 ms |
2140 KB |
Output is correct |
68 |
Correct |
9 ms |
2652 KB |
Output is correct |
69 |
Correct |
14 ms |
4700 KB |
Output is correct |
70 |
Correct |
25 ms |
1880 KB |
Output is correct |
71 |
Correct |
1326 ms |
177372 KB |
Output is correct |
72 |
Correct |
1309 ms |
181172 KB |
Output is correct |
73 |
Correct |
891 ms |
92612 KB |
Output is correct |
74 |
Correct |
1385 ms |
181180 KB |
Output is correct |
75 |
Correct |
648 ms |
75204 KB |
Output is correct |
76 |
Correct |
782 ms |
93376 KB |
Output is correct |
77 |
Correct |
819 ms |
93748 KB |
Output is correct |
78 |
Correct |
1168 ms |
176800 KB |
Output is correct |
79 |
Correct |
0 ms |
344 KB |
Output is correct |
80 |
Correct |
0 ms |
348 KB |
Output is correct |
81 |
Correct |
0 ms |
348 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 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 |
600 KB |
Output is correct |
87 |
Correct |
1 ms |
348 KB |
Output is correct |
88 |
Correct |
1 ms |
604 KB |
Output is correct |
89 |
Correct |
1 ms |
344 KB |
Output is correct |
90 |
Correct |
15 ms |
4860 KB |
Output is correct |
91 |
Correct |
9 ms |
2648 KB |
Output is correct |
92 |
Correct |
9 ms |
2704 KB |
Output is correct |
93 |
Correct |
25 ms |
1884 KB |
Output is correct |
94 |
Correct |
852 ms |
89536 KB |
Output is correct |
95 |
Correct |
1356 ms |
180988 KB |
Output is correct |
96 |
Correct |
1403 ms |
181176 KB |
Output is correct |
97 |
Correct |
1337 ms |
181180 KB |
Output is correct |
98 |
Correct |
1036 ms |
92608 KB |
Output is correct |
99 |
Correct |
1360 ms |
181104 KB |
Output is correct |
100 |
Correct |
1314 ms |
180996 KB |
Output is correct |
101 |
Correct |
1463 ms |
181144 KB |
Output is correct |
102 |
Correct |
1342 ms |
181172 KB |
Output is correct |
103 |
Correct |
912 ms |
93708 KB |
Output is correct |
104 |
Correct |
1257 ms |
172448 KB |
Output is correct |
105 |
Correct |
814 ms |
179896 KB |
Output is correct |