| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1285359 | lmquan | Fire (BOI24_fire) | C++20 | 75 ms | 27836 KiB |
#define taskname ""
#include <bits/stdc++.h>
using namespace std;
const int kMaxLog = 30;
int main() {
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<pair<int, int>> s;
for (int i = 1; i <= n; i++) {
int l, r;
cin >> l >> r;
s.push_back(make_pair(l, r + (r < l ? m : 0)));
}
sort(s.begin(), s.end(), [](pair<int, int> x, pair<int, int> y) {
return (x.first < y.first || (x.first == y.first && x.second > y.second));
});
vector<pair<int, int>> k;
int maxr = 0;
for (auto [l, r] : s) {
if (r <= maxr) {
continue;
}
k.push_back(make_pair(l, r));
maxr = r;
}
vector<vector<int>> jump(kMaxLog, vector<int>(k.size(), -1));
int p = 0;
for (int i = 0; i < k.size(); i++) {
p = max(p, i);
while (p + 1 < k.size() && k[p + 1].first <= k[i].second) {
p++;
}
jump[0][i] = (p != i) ? p : -1;
}
for (int i = 1; i < kMaxLog; i++) {
for (int j = 0; j < k.size(); j++) {
if (jump[i - 1][j] == -1) {
continue;
}
jump[i][j] = (jump[i - 1][j] != -1) ? jump[i - 1][jump[i - 1][j]] : -1;
}
}
int result = m + 1;
for (int i = 0; i < k.size(); i++) {
if (k[i].second >= k[i].first + m) {
result = 1;
break;
}
int c = 1, t = i;
for (int j = kMaxLog - 1; j >= 0; j--) {
if (jump[j][t] != -1 && k[jump[j][t]].second < k[i].first + m - 1) {
c += (1 << j), t = jump[j][t];
}
}
if (jump[0][t] != -1) {
result = min(result, c + 1);
}
}
cout << (result > m ? -1 : result);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
