Submission #1066842

# Submission time Handle Problem Language Result Execution time Memory
1066842 2024-08-20T08:00:06 Z vjudge1 Fire (BOI24_fire) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

constexpr int mxN = 200'000;
int N, M;
pair<int,int> se[mxN + 1];
vector<int> normal;
i64 dp[3 * mxN + 5];

int getNorm(int x) {
    int lo = 0, hi = (int) normal.size() - 1;
    while (lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        if (normal[mid] == x) return mid;
        else if (normal[mid] < x) lo = mid + 1;
        else hi = mid - 1;
    }
    return -1;
}

void solve() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> se[i].first >> se[i].second;
        normal.emplace_back(se[i].first);
        normal.emplace_back(se[i].second);
        if (se[i].second < se[i].first) {
            se[i].second += M;
            normal.emplace_back(se[i].second);
        }
    }

    sort(normal.begin(), normal.end());
    normal.erase(unique(normal.begin(), normal.end()), normal.end());

    for (int i = 0; i < N; i++) {
        se[i].first = getNorm(se[i].first);
        se[i].second = getNorm(se[i].second);
    }
    sort(se, se + N);

    i64 ans = 1LL * (N + 10) * (N + 10);

    for (int i = 0; i < (int) normal.size(); i++) {
        dp[i] = 1LL * i * (N + 10);
    }

    int id = 0;
    priority_queue<pair<int,int>> pq;
    for (int i = 0; i < (int) normal.size(); i++) {
        for (; id < N && se[id].first >= i; id++) {
            pq.push({-se[id].second, -se[id].first});
        }
        if (!pq.empty()) {
            dp[i] = min(dp[i], dp[-pq.top().second] + 1);
            for (; !pq.empty() && -pq.top().first <= i; pq.pop()) {
                int r = -pq.top().first;
                if (normal[r] >= M) {
                    int l = -pq.top().second;
                    ans = min(ans, 1 + dp[l] - dp[getNorm(normal[r] - M)]);
                }
            }
        }
    }

    if (ans > N) ans = -1;
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int tc = 1; 
    //cin >> tc;
    while (tc--) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 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 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -