답안 #1086650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086650 2024-09-11T08:14:19 Z SuPythony Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 31048 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<vector<int>> al;

int main() {
    int n,q; cin>>n>>q;
    vector<pair<int,int>> ev;
    for (int i=0; i<n; i++) {
        int s,e; cin>>s>>e;
        ev.push_back({s,e});
    }
    al.assign(n+1,vector<int>());
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            if (i==j) continue;
            if (ev[j].first<=ev[i].second&&ev[i].second<=ev[j].second) {
                al[i+1].push_back(j+1);
            }
        }
    }
    while (q--) {
        int s,e; cin>>s>>e;
        queue<pair<int,int>> q;
        q.push({s,0});
        vector<int> vis(n+1,0);
        vis[s]=1;
        int ans=-1;
        if (s==e) ans=0;
        while (!q.empty()) {
            auto t=q.front(); q.pop();
            bool f=false;
            for (int v: al[t.first]) {
                if (v==e) {
                    ans=t.second+1;
                    f=true;
                    break;
                } else {
                    if (!vis[v]) {
                        vis[v]=1;
                        q.push({v,t.second+1});
                    }
                }
            }
            if (f) break;
        }
        if (ans==-1) cout<<"impossible\n";
        else cout<<ans<<"\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Execution timed out 1554 ms 5828 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 8 ms 1884 KB Output is correct
8 Correct 8 ms 3160 KB Output is correct
9 Correct 4 ms 4328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 8 ms 1884 KB Output is correct
8 Correct 8 ms 3160 KB Output is correct
9 Correct 4 ms 4328 KB Output is correct
10 Correct 0 ms 428 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 6 ms 1116 KB Output is correct
16 Correct 8 ms 1884 KB Output is correct
17 Correct 8 ms 3164 KB Output is correct
18 Correct 4 ms 4444 KB Output is correct
19 Execution timed out 1571 ms 31048 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 8 ms 1884 KB Output is correct
8 Correct 8 ms 3160 KB Output is correct
9 Correct 4 ms 4328 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 5 ms 1116 KB Output is correct
16 Correct 7 ms 1884 KB Output is correct
17 Correct 8 ms 3164 KB Output is correct
18 Correct 4 ms 4292 KB Output is correct
19 Execution timed out 1595 ms 5640 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1558 ms 5840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Execution timed out 1554 ms 5828 KB Time limit exceeded
3 Halted 0 ms 0 KB -