답안 #579728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579728 2022-06-19T16:56:20 Z jasmin Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 524288 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int inf=1e18;

int find_dist(int v, int ende, vector<vector<int> >& adi, vector<pair<int,int> >& e){
    if(e[ende].second<e[v].second) return inf;
    if(v==ende) return 0;

    int best=v;
    for(auto u: adi[v]){
        if(u==ende){
            best=u;
            break;
        }

        if(e[best].second<e[u].second && e[u].second<=e[ende].second){
            best=u;
        }
    }

    if(best==ende) return 1;
    if(e[best].second==e[v].second) return inf;

    int ans=find_dist(best, ende, adi, e);
    if(ans==inf) return inf;
    return ans+1;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;
    vector<pair<int,int> > e(n);
    map<int, pair<vector<int>, vector<int> > > time;
    for(int i=0; i<n; i++){
        int s, t;
        cin>> s >> t;
        e[i]={s, t};
        time[s].first.push_back(i);
        time[t].second.push_back(i);
    }

    vector<vector<int> > adi(n);
    set<int> active;
    for(auto m: time){
        for(auto e: m.second.first){
            active.insert(e);
        }
        
        for(auto e: m.second.second){
            for(auto x: active){
                if(e==x) continue;
                adi[e].push_back(x);
            }
        }
        for(auto e: m.second.second){
            active.erase(e);
        }
    }
    active.clear();
    time.clear();

    
    for(int i=0; i<q; i++){
        int s, t;
        cin >> s >> t;
        int ans=find_dist(s-1, t-1, adi, e);
        if(ans==inf){
            cout << "impossible\n";
        }
        else{
            cout << ans << "\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1576 ms 26012 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 4 ms 2004 KB Output is correct
7 Correct 6 ms 3796 KB Output is correct
8 Correct 9 ms 5784 KB Output is correct
9 Correct 11 ms 8348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 4 ms 2004 KB Output is correct
7 Correct 6 ms 3796 KB Output is correct
8 Correct 9 ms 5784 KB Output is correct
9 Correct 11 ms 8348 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 3 ms 2004 KB Output is correct
16 Correct 8 ms 3796 KB Output is correct
17 Correct 9 ms 5800 KB Output is correct
18 Correct 11 ms 8348 KB Output is correct
19 Execution timed out 1590 ms 54960 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 4 ms 2004 KB Output is correct
7 Correct 6 ms 3796 KB Output is correct
8 Correct 9 ms 5784 KB Output is correct
9 Correct 11 ms 8348 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 568 KB Output is correct
14 Correct 2 ms 548 KB Output is correct
15 Correct 4 ms 2004 KB Output is correct
16 Correct 7 ms 3796 KB Output is correct
17 Correct 9 ms 5844 KB Output is correct
18 Correct 15 ms 8404 KB Output is correct
19 Correct 693 ms 26528 KB Output is correct
20 Correct 356 ms 30504 KB Output is correct
21 Runtime error 1261 ms 524288 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1602 ms 26060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1576 ms 26012 KB Time limit exceeded
3 Halted 0 ms 0 KB -