Submission #721641

# Submission time Handle Problem Language Result Execution time Memory
721641 2023-04-11T06:02:52 Z drdilyor Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 7316 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;


const int inf = 1e9 + 1e5;
struct event {
    int l, r, i;
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<event> ev(n), og;
    map<int,int> comp;
    int _i = 0;
    for (auto& [s, e, i] : ev) {
        cin >> s >> e;
        comp[s] = comp[e] = 0;
        i = _i++;
    }
    int k = 0;
    for (auto& mp : comp)
        mp.second = k++;
    for (auto& [s, e, i] : ev)
        s = comp[s], e = comp[e];

    og = ev;
    sort(ev.begin(), ev.end(), [&](auto& a, auto& b) {
        return a.r == b.r ? a.l < b.l : a.r < b.r ;
    });

    //for (auto [l, r, i] : ev) cout << l << ' ' << r << ' ' << i << "\n";

    while (m--) {
        int s, e;
        cin >> s >> e;
        s--;e--;

        if (s == e) {
            cout << "0\n";
            continue;
        }


        int si = 0, ei;
        for (int j = 0; j < n; j++) {
            if (ev[j].i == s) si = j;
            if (ev[j].i == e) ei = j;
        }
        //cout << "s,e = " << si << ' '<< ei << '\n';

        int res = 0;
        bool found = 0;
        int left = ev[ei].l;
        set<int> st;
        for (int j = ei-1; j >= 0; j--) {
            auto [l,r,_i] = ev[j];
            if (r < left) {
                if (st.empty()) break;
                left = *st.begin();
                st.clear();
                res++;
            }
            if (j == si) {
                found = 1;
                break;
            }
            st.insert(l);
        }


        if (found) cout << 1+res << '\n';
        else cout << "impossible\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1578 ms 7316 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 340 KB Output is correct
4 Incorrect 3 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 340 KB Output is correct
4 Incorrect 3 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 340 KB Output is correct
4 Incorrect 3 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1563 ms 7272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1578 ms 7316 KB Time limit exceeded
3 Halted 0 ms 0 KB -