답안 #937640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
937640 2024-03-04T10:03:06 Z LucaIlie Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 8516 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5;
const int MAX_T = 2e5;

struct event {
    int i, s, e;
};

int prv[MAX_N];
event events[MAX_N];
map<int, int> nrm;

bool canSwitch( event a, event b ) {
    return (b.s <= a.e && a.e <= b.e);
}

int main() {
    int n, q;

    cin >> n >> q;
    for ( int i = 1; i <= n; i++ ) {
        cin >> events[i].s >> events[i].e;
        nrm[events[i].s] = nrm[events[i].e] = 1;
        events[i].i = i + 1;
    }
    int t = 0;
    for ( auto p: nrm )
        nrm[p.first] = ++t;
    for ( int i = 1; i <= n; i++ ) {
        events[i].s = nrm[events[i].s];
        events[i].e = nrm[events[i].e];
    }

    for ( int i = 1; i <= n; i++ ) {
        prv[i] = i;
        for ( int j = 1; j <= n; j++ ) {
            if ( canSwitch( events[j], events[i] )  ) {
                if ( events[j].s < events[prv[i]].s )
                    prv[i] = j;
            }
        }
    }

    while ( q-- ) {
        int s, e, x = 1;
        cin >> s >> e;

        int i = e;
        while ( (!canSwitch( events[s], events[i] )) && prv[i] != i ) {
            i = prv[i];
            x++;
        }


        if ( s == e )
            cout << 0 << "\n";
        else if ( canSwitch( events[s], events[i] ) )
            cout << x << "\n";
        else
            cout << "impossible\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1542 ms 8268 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 5 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 5 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 4 ms 360 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Correct 5 ms 576 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 814 ms 2200 KB Output is correct
20 Execution timed out 1533 ms 2204 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 5 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 4 ms 516 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
16 Correct 5 ms 572 KB Output is correct
17 Correct 4 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Execution timed out 1555 ms 8260 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1540 ms 8516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1542 ms 8268 KB Time limit exceeded
3 Halted 0 ms 0 KB -