# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1028194 |
2024-07-19T15:05:06 Z |
Issa |
Fire (BOI24_fire) |
C++17 |
|
62 ms |
23240 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 = 3e5 + 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] = j;
}
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;
}
# |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
464 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
39 ms |
20096 KB |
Output is correct |
16 |
Correct |
57 ms |
22204 KB |
Output is correct |
17 |
Correct |
61 ms |
23240 KB |
Output is correct |
18 |
Correct |
61 ms |
23240 KB |
Output is correct |
19 |
Correct |
62 ms |
23128 KB |
Output is correct |
20 |
Correct |
55 ms |
22220 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |