# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1113976 |
2024-11-18T03:06:47 Z |
thelegendary08 |
Fire (BOI24_fire) |
C++17 |
|
182 ms |
79396 KB |
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vc vector<char>
#define vb vector<bool>
#define mii map<int,int>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define in(a) int a; cin>>a
#define in2(a,b) int a,b; cin>>a>>b
#define in3(a,b,c) int a,b,c; cin>>a>>b>>c
#define in4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d
#define vin(v,n); vi v(n); f0r(i,n){cin>>v[i];}
#define out(a) cout<<a<<'\n'
#define out2(a,b) cout<<a<<' '<<b<<'\n'
#define out3(a,b,c) cout<<a<<' '<<b<<' '<<c<<'\n'
#define out4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<'\n'
#define vout(v) for(auto u : v){cout<<u<<' ';} cout<<'\n'
#define dout(a) cout<<a<<' '<<#a<<'\n'
#define dout2(a,b) cout<<a<<' '<<#a<<' '<<b<<' '<<#b<<'\n'
#define yn(x); if(x){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';}
const int leg = 1e9 + 7;
const int mod = 998244353;
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
//ifstream cin(".in");
//ofstream cout(".out");
in2(n,m);
vpii v;
f0r(i,n){
in2(a,b);
v.pb({a,b});
}
sort(all(v));
vpii w;
int mx = -1;
f0r(i, n){
if(v[i].second + (v[i].first > v[i].second) * m > mx){
w.pb(v[i]);
mx = v[i].second + (v[i].first > v[i].second) * m;
}
}
n = w.size();
f0r(i,n){
if(w[i].first > w[i].second)w[i].second += m;
}
f0r(i,n){
w.pb({w[i].first + m, w[i].second + m});
}
/*
f0r(i, n){
out2(w[i].first, w[i].second);
}
*/
int ptr = 0;
vi nxt(n*2);
f0r(i, n*2){
while(w[i].first <= w[ptr].first && w[ptr].first <= w[i].second){
ptr++;
ptr %= 2 * n;
}
if(ptr != 0)nxt[i] = ptr - 1;
else nxt[i] = 2 * n-1;
}
//vout(nxt);
int jmp[n*2][20];
f0r(i, n*2){
jmp[i][0] = nxt[i];
}
FOR(i, 1, 20){
f0r(j,n*2){
jmp[j][i] = jmp[jmp[j][i-1]][i-1];
}
}
f0r(i, n){
//out2(jmp[i][0].first, jmp[i][0].second);
}
//out("");
f0r(i, n){
//out2(jmp[i][4].first, jmp[i][4].second);
}
int ans = 4e18;
f0r(i, n){
int start = w[i].first;
if(w[jmp[i][0]].second >= start + m){
ans = min(ans, 2ll);
}
else{
int cur = 0;
int dex = i;
for(int j = 19; j>=0; j--){
if(w[jmp[dex][j]].second < start + m){
cur += (1 << j);
dex = jmp[dex][j];
}
/*
if(loops == 0){
if(jmp[dex][j].second == 1 && w[jmp[dex][j].first].second < w[i].first){
cur += (1 << j);
loops++;
dex = jmp[dex][j].first;
//out("path 1");
}
else if(jmp[dex][j].second == 0){
cur += (1 << j);
dex = jmp[dex][j].first;
//out("path 2");
}
}
else if(loops == 1){
if(jmp[dex][j].second == 0 && w[jmp[dex][j].first].second < w[i].first){
cur += (1 << j);
dex = jmp[dex][j].first;
//out("path 3");
}
}
*/
//dout2(loops, dex);
}
//out(cur);
if(cur != (1 << 20) - 1)ans = min(ans, cur + 2);
}
}
if(ans != 4e18)out(ans);
else out(-1);
}
# |
Verdict |
Execution time |
Memory |
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 |
456 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 |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
380 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 |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
456 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 |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
380 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 |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
508 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
604 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 |
508 KB |
Output is correct |
37 |
Correct |
1 ms |
352 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
456 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 |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
380 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 |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
508 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
604 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 |
508 KB |
Output is correct |
37 |
Correct |
1 ms |
352 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
2 ms |
848 KB |
Output is correct |
40 |
Correct |
4 ms |
2252 KB |
Output is correct |
41 |
Correct |
4 ms |
2256 KB |
Output is correct |
42 |
Correct |
5 ms |
2264 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
2264 KB |
Output is correct |
45 |
Correct |
4 ms |
2252 KB |
Output is correct |
46 |
Correct |
4 ms |
2340 KB |
Output is correct |
47 |
Correct |
3 ms |
744 KB |
Output is correct |
48 |
Correct |
2 ms |
592 KB |
Output is correct |
49 |
Correct |
2 ms |
1360 KB |
Output is correct |
50 |
Correct |
4 ms |
2412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
508 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
468 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 |
460 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 |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
5 ms |
2388 KB |
Output is correct |
16 |
Correct |
4 ms |
2252 KB |
Output is correct |
17 |
Correct |
2 ms |
848 KB |
Output is correct |
18 |
Correct |
4 ms |
2252 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
24 ms |
5380 KB |
Output is correct |
21 |
Correct |
63 ms |
16972 KB |
Output is correct |
22 |
Correct |
59 ms |
14520 KB |
Output is correct |
23 |
Correct |
162 ms |
78376 KB |
Output is correct |
24 |
Correct |
140 ms |
63020 KB |
Output is correct |
25 |
Correct |
66 ms |
22464 KB |
Output is correct |
26 |
Correct |
96 ms |
43060 KB |
Output is correct |
27 |
Correct |
159 ms |
79324 KB |
Output is correct |
28 |
Correct |
55 ms |
12724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
504 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 |
428 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 |
592 KB |
Output is correct |
12 |
Correct |
4 ms |
2252 KB |
Output is correct |
13 |
Correct |
5 ms |
2252 KB |
Output is correct |
14 |
Correct |
4 ms |
2252 KB |
Output is correct |
15 |
Correct |
31 ms |
5248 KB |
Output is correct |
16 |
Correct |
182 ms |
78368 KB |
Output is correct |
17 |
Correct |
169 ms |
79288 KB |
Output is correct |
18 |
Correct |
166 ms |
79272 KB |
Output is correct |
19 |
Correct |
175 ms |
79396 KB |
Output is correct |
20 |
Correct |
161 ms |
78380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
456 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 |
456 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
380 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 |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
508 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
604 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 |
508 KB |
Output is correct |
37 |
Correct |
1 ms |
352 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
2 ms |
848 KB |
Output is correct |
40 |
Correct |
4 ms |
2252 KB |
Output is correct |
41 |
Correct |
4 ms |
2256 KB |
Output is correct |
42 |
Correct |
5 ms |
2264 KB |
Output is correct |
43 |
Correct |
2 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
2264 KB |
Output is correct |
45 |
Correct |
4 ms |
2252 KB |
Output is correct |
46 |
Correct |
4 ms |
2340 KB |
Output is correct |
47 |
Correct |
3 ms |
744 KB |
Output is correct |
48 |
Correct |
2 ms |
592 KB |
Output is correct |
49 |
Correct |
2 ms |
1360 KB |
Output is correct |
50 |
Correct |
4 ms |
2412 KB |
Output is correct |
51 |
Correct |
1 ms |
508 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
468 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 |
460 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 |
336 KB |
Output is correct |
62 |
Correct |
1 ms |
336 KB |
Output is correct |
63 |
Correct |
1 ms |
592 KB |
Output is correct |
64 |
Correct |
1 ms |
336 KB |
Output is correct |
65 |
Correct |
5 ms |
2388 KB |
Output is correct |
66 |
Correct |
4 ms |
2252 KB |
Output is correct |
67 |
Correct |
2 ms |
848 KB |
Output is correct |
68 |
Correct |
4 ms |
2252 KB |
Output is correct |
69 |
Correct |
2 ms |
592 KB |
Output is correct |
70 |
Correct |
24 ms |
5380 KB |
Output is correct |
71 |
Correct |
63 ms |
16972 KB |
Output is correct |
72 |
Correct |
59 ms |
14520 KB |
Output is correct |
73 |
Correct |
162 ms |
78376 KB |
Output is correct |
74 |
Correct |
140 ms |
63020 KB |
Output is correct |
75 |
Correct |
66 ms |
22464 KB |
Output is correct |
76 |
Correct |
96 ms |
43060 KB |
Output is correct |
77 |
Correct |
159 ms |
79324 KB |
Output is correct |
78 |
Correct |
55 ms |
12724 KB |
Output is correct |
79 |
Correct |
1 ms |
336 KB |
Output is correct |
80 |
Correct |
1 ms |
504 KB |
Output is correct |
81 |
Correct |
1 ms |
336 KB |
Output is correct |
82 |
Correct |
1 ms |
336 KB |
Output is correct |
83 |
Correct |
1 ms |
336 KB |
Output is correct |
84 |
Correct |
1 ms |
336 KB |
Output is correct |
85 |
Correct |
1 ms |
428 KB |
Output is correct |
86 |
Correct |
1 ms |
336 KB |
Output is correct |
87 |
Correct |
1 ms |
336 KB |
Output is correct |
88 |
Correct |
1 ms |
336 KB |
Output is correct |
89 |
Correct |
1 ms |
592 KB |
Output is correct |
90 |
Correct |
4 ms |
2252 KB |
Output is correct |
91 |
Correct |
5 ms |
2252 KB |
Output is correct |
92 |
Correct |
4 ms |
2252 KB |
Output is correct |
93 |
Correct |
31 ms |
5248 KB |
Output is correct |
94 |
Correct |
182 ms |
78368 KB |
Output is correct |
95 |
Correct |
169 ms |
79288 KB |
Output is correct |
96 |
Correct |
166 ms |
79272 KB |
Output is correct |
97 |
Correct |
175 ms |
79396 KB |
Output is correct |
98 |
Correct |
161 ms |
78380 KB |
Output is correct |
99 |
Correct |
74 ms |
28728 KB |
Output is correct |
100 |
Correct |
55 ms |
14524 KB |
Output is correct |
101 |
Correct |
157 ms |
78132 KB |
Output is correct |
102 |
Correct |
131 ms |
65576 KB |
Output is correct |
103 |
Correct |
172 ms |
79396 KB |
Output is correct |
104 |
Correct |
75 ms |
17844 KB |
Output is correct |
105 |
Correct |
106 ms |
42032 KB |
Output is correct |