답안 #579732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579732 2022-06-19T17:01:02 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;
}*/
int find_dist(int start, int ende, vector<vector<int> >& adi, vector<pair<int,int> >& e){
    if(start==ende) return 0;
    if(e[ende].second<e[start].second) return inf;

    int v=start;
    int ans=0;
    while(v!=ende){

        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==v) return inf;

        ans++;
        v=best;
    }
    return ans;
}


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 1585 ms 23004 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 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 7 ms 3796 KB Output is correct
8 Correct 10 ms 5844 KB Output is correct
9 Correct 11 ms 8356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 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 7 ms 3796 KB Output is correct
8 Correct 10 ms 5844 KB Output is correct
9 Correct 11 ms 8356 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 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 3 ms 2004 KB Output is correct
16 Correct 7 ms 3748 KB Output is correct
17 Correct 9 ms 5844 KB Output is correct
18 Correct 10 ms 8404 KB Output is correct
19 Execution timed out 1589 ms 55136 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 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 7 ms 3796 KB Output is correct
8 Correct 10 ms 5844 KB Output is correct
9 Correct 11 ms 8356 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 4 ms 2004 KB Output is correct
16 Correct 6 ms 3796 KB Output is correct
17 Correct 10 ms 5900 KB Output is correct
18 Correct 12 ms 8424 KB Output is correct
19 Correct 522 ms 23016 KB Output is correct
20 Correct 263 ms 27748 KB Output is correct
21 Runtime error 1236 ms 524288 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1601 ms 23012 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 1585 ms 23004 KB Time limit exceeded
3 Halted 0 ms 0 KB -