Submission #721789

# Submission time Handle Problem Language Result Execution time Memory
721789 2023-04-11T07:18:50 Z drdilyor Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 524288 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[a,b,c] : ev) cout << a << ' ' << b << ' ' << c <<'\n';
 
    vector ans(n, vector(n, inf));

    for (int ei = n-1; ei >= 0; ei--) {
        int res = 0;
        int left = ev[ei].l;
        set<int> st;
        for (int j = n-1; j >= 0; j--) {
            auto [l,r,_i] = ev[j];
            if (r > ev[ei].r) continue;
            if (r < left) {
                if (st.empty()) break;
                left = *st.begin();
                if (r < left) break;
                st.clear();
                res++;
            }
            ans[ei][j] = res + 1;
            st.insert(l);
        }
    }
 
    while (m--) {
        int s, e;
        cin >> s >> e;
        s--;e--;
 
        if (s == e) {
            cout << "0\n";
            continue;
        }
 
 
        int si = 0, ei = 0;
        for (int j = 0; j < n; j++) {
            if (ev[j].i == s) si = j;
            if (ev[j].i == e) ei = j;
        }
 
        if (ans[ei][si] < inf) cout << ans[ei][si] << '\n';
        else cout << "impossible\n";
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 496 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 39 ms 4328 KB Output is correct
4 Correct 12 ms 4308 KB Output is correct
5 Correct 17 ms 4364 KB Output is correct
6 Correct 30 ms 4324 KB Output is correct
7 Correct 70 ms 4308 KB Output is correct
8 Correct 51 ms 4392 KB Output is correct
9 Correct 10 ms 4276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 39 ms 4328 KB Output is correct
4 Correct 12 ms 4308 KB Output is correct
5 Correct 17 ms 4364 KB Output is correct
6 Correct 30 ms 4324 KB Output is correct
7 Correct 70 ms 4308 KB Output is correct
8 Correct 51 ms 4392 KB Output is correct
9 Correct 10 ms 4276 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 284 KB Output is correct
12 Correct 20 ms 4308 KB Output is correct
13 Correct 18 ms 4308 KB Output is correct
14 Correct 28 ms 4308 KB Output is correct
15 Correct 35 ms 4308 KB Output is correct
16 Correct 65 ms 4412 KB Output is correct
17 Correct 59 ms 4392 KB Output is correct
18 Correct 9 ms 4180 KB Output is correct
19 Correct 977 ms 99664 KB Output is correct
20 Correct 1004 ms 100168 KB Output is correct
21 Correct 1054 ms 100560 KB Output is correct
22 Execution timed out 1512 ms 100568 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 39 ms 4328 KB Output is correct
4 Correct 12 ms 4308 KB Output is correct
5 Correct 17 ms 4364 KB Output is correct
6 Correct 30 ms 4324 KB Output is correct
7 Correct 70 ms 4308 KB Output is correct
8 Correct 51 ms 4392 KB Output is correct
9 Correct 10 ms 4276 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 17 ms 4324 KB Output is correct
13 Correct 11 ms 4308 KB Output is correct
14 Correct 17 ms 4364 KB Output is correct
15 Correct 29 ms 4360 KB Output is correct
16 Correct 62 ms 4468 KB Output is correct
17 Correct 56 ms 4388 KB Output is correct
18 Correct 9 ms 4180 KB Output is correct
19 Runtime error 370 ms 524288 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 380 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 496 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -