# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1059288 |
2024-08-14T20:28:45 Z |
ZeroCool |
Fire (BOI24_fire) |
C++14 |
|
387 ms |
54988 KB |
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define int long long
#define ld long double
#define crash assert(69 == 420)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 3000;
const int K = 300;
const int LOG = 30;
/*
Bidikland can be represneted like a circle with a lot of of smaller circles inside it. The bigest circle represent the border, and the smaller represent the municipalities.
No two circles can interesect but the can be contained within eachother. Lets defne the territory of municipality as their circle with the smaller circles contained inside it removed (see drawing for reference)
On the edge of any two mmunicipalities there are pay tolls, each toll costs exactly one Bidikdollar. One day Bidik realized tha the machines at all of the tolls are broken and he needed to fix them.
He hired Viktors company (con world) to send men to fix them. This is how to process of fixing goes: A mechanic starts from a municipality without any municipalities within it, he moves through the municipalities and needs to end at another municipality with no municipalities within it(the path he takes must be a simple path), on this trip he fixes all the tolls he passes but also has to pay them, so the cost of the trip is the number of tolls passed. What is minimal cost Bidik has to spend on tolls in order to fix all of them?
*/
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
int n, m;
cin>>n>>m;
vector<ar<int, 2>> v;
int s[n], e[n];
set<int>ss = {0, m};
for(int i= 0;i <n ;i++){
cin>>s[i]>>e[i];
ss.insert(s[i]);
ss.insert(e[i]);
}
map<int,int> cmp;
for(auto u: ss)cmp[u] = cmp.size();
m = cmp.size();
int mx[m + 1];
memset(mx, 0,sizeof mx);
for(int i = 0;i <n;i++){
s[i] = cmp[s[i]], e[i] = cmp[e[i]];
if(s[i] > e[i])mx[s[i]] = m, v.push_back({s[i], e[i]});
mx[s[i]] = max(mx[s[i]], e[i]);
}
for(int i =1 ;i <= m;i++)mx[i] = max(mx[i], mx[i - 1]);
if(v.empty()){
cout<<-1;
return 0;
}
int ans = INF;
for(auto [a, b]: v){
int cnt = 1;
int u = b;
while(u < a){
if(mx[u] <= u)break;
u = mx[u];
++cnt;
}
if(u >= a)ans = min(ans, cnt);
}
if(ans >= INF)ans = -1;
cout<<ans;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:52:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
52 | for(auto [a, b]: v){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 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 |
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 |
348 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 |
456 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 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 |
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 |
348 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 |
456 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
460 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 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 |
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 |
348 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 |
456 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
460 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
4 ms |
1628 KB |
Output is correct |
40 |
Correct |
4 ms |
1624 KB |
Output is correct |
41 |
Correct |
4 ms |
1800 KB |
Output is correct |
42 |
Correct |
4 ms |
1116 KB |
Output is correct |
43 |
Correct |
3 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1072 KB |
Output is correct |
45 |
Correct |
3 ms |
1116 KB |
Output is correct |
46 |
Correct |
3 ms |
1116 KB |
Output is correct |
47 |
Correct |
4 ms |
1628 KB |
Output is correct |
48 |
Correct |
4 ms |
1784 KB |
Output is correct |
49 |
Correct |
3 ms |
1716 KB |
Output is correct |
50 |
Correct |
4 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
5 ms |
1796 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
1180 KB |
Output is correct |
19 |
Correct |
4 ms |
1628 KB |
Output is correct |
20 |
Correct |
19 ms |
6568 KB |
Output is correct |
21 |
Correct |
377 ms |
54300 KB |
Output is correct |
22 |
Correct |
369 ms |
54356 KB |
Output is correct |
23 |
Correct |
209 ms |
29780 KB |
Output is correct |
24 |
Correct |
327 ms |
54356 KB |
Output is correct |
25 |
Correct |
211 ms |
26568 KB |
Output is correct |
26 |
Correct |
192 ms |
30804 KB |
Output is correct |
27 |
Correct |
196 ms |
30804 KB |
Output is correct |
28 |
Correct |
291 ms |
52988 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
424 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1116 KB |
Output is correct |
14 |
Correct |
3 ms |
1116 KB |
Output is correct |
15 |
Correct |
17 ms |
6372 KB |
Output is correct |
16 |
Correct |
203 ms |
29912 KB |
Output is correct |
17 |
Correct |
387 ms |
54292 KB |
Output is correct |
18 |
Correct |
375 ms |
54988 KB |
Output is correct |
19 |
Correct |
299 ms |
54200 KB |
Output is correct |
20 |
Correct |
199 ms |
29776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 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 |
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 |
348 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 |
456 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
460 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
4 ms |
1628 KB |
Output is correct |
40 |
Correct |
4 ms |
1624 KB |
Output is correct |
41 |
Correct |
4 ms |
1800 KB |
Output is correct |
42 |
Correct |
4 ms |
1116 KB |
Output is correct |
43 |
Correct |
3 ms |
860 KB |
Output is correct |
44 |
Correct |
3 ms |
1072 KB |
Output is correct |
45 |
Correct |
3 ms |
1116 KB |
Output is correct |
46 |
Correct |
3 ms |
1116 KB |
Output is correct |
47 |
Correct |
4 ms |
1628 KB |
Output is correct |
48 |
Correct |
4 ms |
1784 KB |
Output is correct |
49 |
Correct |
3 ms |
1716 KB |
Output is correct |
50 |
Correct |
4 ms |
1372 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
600 KB |
Output is correct |
53 |
Correct |
0 ms |
344 KB |
Output is correct |
54 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
600 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
5 ms |
1796 KB |
Output is correct |
66 |
Correct |
3 ms |
1116 KB |
Output is correct |
67 |
Correct |
2 ms |
860 KB |
Output is correct |
68 |
Correct |
3 ms |
1180 KB |
Output is correct |
69 |
Correct |
4 ms |
1628 KB |
Output is correct |
70 |
Correct |
19 ms |
6568 KB |
Output is correct |
71 |
Correct |
377 ms |
54300 KB |
Output is correct |
72 |
Correct |
369 ms |
54356 KB |
Output is correct |
73 |
Correct |
209 ms |
29780 KB |
Output is correct |
74 |
Correct |
327 ms |
54356 KB |
Output is correct |
75 |
Correct |
211 ms |
26568 KB |
Output is correct |
76 |
Correct |
192 ms |
30804 KB |
Output is correct |
77 |
Correct |
196 ms |
30804 KB |
Output is correct |
78 |
Correct |
291 ms |
52988 KB |
Output is correct |
79 |
Correct |
0 ms |
348 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 |
424 KB |
Output is correct |
86 |
Correct |
0 ms |
348 KB |
Output is correct |
87 |
Correct |
0 ms |
348 KB |
Output is correct |
88 |
Correct |
0 ms |
348 KB |
Output is correct |
89 |
Correct |
0 ms |
344 KB |
Output is correct |
90 |
Correct |
4 ms |
1628 KB |
Output is correct |
91 |
Correct |
3 ms |
1116 KB |
Output is correct |
92 |
Correct |
3 ms |
1116 KB |
Output is correct |
93 |
Correct |
17 ms |
6372 KB |
Output is correct |
94 |
Correct |
203 ms |
29912 KB |
Output is correct |
95 |
Correct |
387 ms |
54292 KB |
Output is correct |
96 |
Correct |
375 ms |
54988 KB |
Output is correct |
97 |
Correct |
299 ms |
54200 KB |
Output is correct |
98 |
Correct |
199 ms |
29776 KB |
Output is correct |
99 |
Correct |
334 ms |
54608 KB |
Output is correct |
100 |
Correct |
353 ms |
54152 KB |
Output is correct |
101 |
Correct |
296 ms |
54236 KB |
Output is correct |
102 |
Correct |
309 ms |
54348 KB |
Output is correct |
103 |
Correct |
209 ms |
30916 KB |
Output is correct |
104 |
Correct |
267 ms |
51940 KB |
Output is correct |
105 |
Correct |
178 ms |
52976 KB |
Output is correct |