답안 #579726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579726 2022-06-19T16:54:19 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){
                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";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1595 ms 26036 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 528 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 5796 KB Output is correct
9 Correct 11 ms 8412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 528 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 5796 KB Output is correct
9 Correct 11 ms 8412 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 1 ms 468 KB Output is correct
14 Correct 2 ms 468 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 12 ms 8404 KB Output is correct
19 Execution timed out 1574 ms 55172 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 528 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 5796 KB Output is correct
9 Correct 11 ms 8412 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 1 ms 468 KB Output is correct
14 Correct 2 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 8 ms 5820 KB Output is correct
18 Correct 11 ms 8412 KB Output is correct
19 Correct 979 ms 26548 KB Output is correct
20 Correct 380 ms 30540 KB Output is correct
21 Runtime error 1267 ms 524288 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1568 ms 26072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1595 ms 26036 KB Time limit exceeded
3 Halted 0 ms 0 KB -