답안 #971967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971967 2024-04-29T15:30:52 Z idas Event Hopping (BOI22_events) C++11
10 / 100
1500 ms 128476 KB
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) int((x).size())
#define pb push_back
#define s second
#define f first

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;

const int INF=1e9;

const int N=5010;
int n, q, s[N], e[N], d[N][N];
vi ad[N];

int main()
{
    FAST_IO;
    cin >> n >> q;
    FOR(i, 0, n)
    {
        cin >> s[i] >> e[i];
    }

    FOR(i, 0, n)
    {
        FOR(j, 0, n)
        {
            if(i==j) continue;
            if(s[j]<=e[i] && e[i]<=e[j]){
                ad[i].pb(j);
//                cout << i << " -> " << j << '\n';
            }
        }
    }

    FOR(i, 0, n) FOR(j, 0, n) if(i!=j) d[i][j]=-1;

    FOR(i, 0, n)
    {
        queue<int> q; q.push(i);
        while(!q.empty()){
            int u=q.front(); q.pop();
            for(auto x : ad[u]){
                if(d[i][x]==-1){
                    d[i][x]=d[i][u]+1;
                    q.push(x);
                }
            }
        }
    }

    while(q--){
        int a, b; cin >> a >> b; --a; --b;
        if(d[a][b]==-1){
            cout << "impossible\n";
        }
        else{
            cout << d[a][b] << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Runtime error 5 ms 1116 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 14 ms 21084 KB Output is correct
4 Correct 9 ms 21084 KB Output is correct
5 Correct 14 ms 21080 KB Output is correct
6 Correct 42 ms 21852 KB Output is correct
7 Correct 131 ms 22776 KB Output is correct
8 Correct 153 ms 23908 KB Output is correct
9 Correct 771 ms 25176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 14 ms 21084 KB Output is correct
4 Correct 9 ms 21084 KB Output is correct
5 Correct 14 ms 21080 KB Output is correct
6 Correct 42 ms 21852 KB Output is correct
7 Correct 131 ms 22776 KB Output is correct
8 Correct 153 ms 23908 KB Output is correct
9 Correct 771 ms 25176 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 12 ms 21120 KB Output is correct
13 Correct 9 ms 21080 KB Output is correct
14 Correct 12 ms 21092 KB Output is correct
15 Correct 44 ms 21952 KB Output is correct
16 Correct 119 ms 22620 KB Output is correct
17 Correct 156 ms 23828 KB Output is correct
18 Correct 764 ms 25156 KB Output is correct
19 Execution timed out 1555 ms 128476 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 14 ms 21084 KB Output is correct
4 Correct 9 ms 21084 KB Output is correct
5 Correct 14 ms 21080 KB Output is correct
6 Correct 42 ms 21852 KB Output is correct
7 Correct 131 ms 22776 KB Output is correct
8 Correct 153 ms 23908 KB Output is correct
9 Correct 771 ms 25176 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 11 ms 21168 KB Output is correct
13 Correct 9 ms 21084 KB Output is correct
14 Correct 12 ms 21084 KB Output is correct
15 Correct 42 ms 21724 KB Output is correct
16 Correct 121 ms 22760 KB Output is correct
17 Correct 144 ms 23816 KB Output is correct
18 Correct 808 ms 25156 KB Output is correct
19 Runtime error 4 ms 1112 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1116 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Runtime error 5 ms 1116 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -