Submission #579723

# Submission time Handle Problem Language Result Execution time Memory
579723 2022-06-19T16:49:23 Z jasmin Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 26080 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(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){
            best=u;
        }
    }

    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){
                adi[e].push_back(x);
            }
        }
        for(auto e: m.second.second){
            active.erase(e);
        }
    }

    
    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";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1572 ms 26080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -