답안 #746015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746015 2023-05-21T10:35:13 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 4052 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

const ll mod = 1e9 + 7;

int c[100100], hely[100100];

struct P
{
    int poz, id;
    bool veg;
};

bool cmp(P& lhs, P& rhs){
    if(lhs.poz != rhs.poz){
        return lhs.poz < rhs.poz;
    }
    return lhs.veg < rhs.veg;
}

int kov[100100] = {0}, be[100100] = {0};

vector<int> g[100100];

int main(){
    int n, q;
    cin >> n >> q;
    vector<pair<int,int>> v(n + 1);
    for(int i = 1; i <= n; ++i){
        cin >> v[i].first >> v[i].second;
    }
    for(int i = 1;  i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            if(i == j) continue;
            if(v[j].first <= v[i].second && v[i].second < v[j].second){
                g[i].push_back(j);
                cerr << "el: " << i << " " << j << endl;
                ++be[j];
            }
        }
    }
    vector<int> topsort = {0};
    queue<int> s;
    for(int i = 1; i <= n; ++i){
        if(be[i] == 0){
            s.push(i);
        }
    }
    while(!s.empty()){
        auto p = s.front(); s.pop();
        topsort.push_back(p);
        for(auto i : g[p]){
            --be[i];
            if(be[i] == 0) s.push(i);
        }
    }
    vector<int> poz(n + 1);
    for(int i = 1; i <= n; ++i){
        cerr << topsort[i] << endl;
        poz[topsort[i]] = i;
    }
    while(q--){
        int a, b;
        cin >> a >> b;
        vector<int> dp(n + 1, 1e9);
        dp[poz[a]] = 0;
        for(int i = poz[a]; i <= n; ++i){
            for(auto j : g[topsort[i]]){
                dp[poz[j]] = min(dp[poz[j]], dp[i] + 1);
            }
        }
        if(dp[poz[b]] == 1e9){
            cout << "impossible" << endl;
        }
        else{
            cout << dp[poz[b]] << endl;
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1559 ms 4052 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -