답안 #589009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589009 2022-07-04T08:49:58 Z radal Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 461100 KB
#include <bits/stdc++.h>
//#pragma GCC target("sse,sse2,sse4,avx2")
//#pragma GCC optimize("unroll-loops,O2")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 1e5+10,mod = 1e9+7,inf = 1e9+10,sq = 90;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
    if (a+b < 0) return a+b+mod;
    return a+b;
}
 
inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k >>= 1;
    } 
    return z; 
}
int nxt[N][20];
pll a[N];
int par[N],d[N];
vector<int> adj[N];
map<int,vector<int>> st,en;
void bfs(int v){
    par[v] = v;
    d[v] = 0;
    queue<int> q;
    q.push(v);
    while (!q.empty()){
        int u = q.front();
        q.pop();
        for (int w : adj[u]){
            if (par[w] == -1){
                par[w] = v;
                d[w] = d[u]+1;
            }
        }
    }
}
int main(){
    ios :: sync_with_stdio(0); cin.tie(0);
    int n,q;
    cin >> n >> q;
    vector<int> ve;
    rep(i,1,n+1){
        cin >> a[i].X >> a[i].Y;
        ve.pb(a[i].X);
        ve.pb(a[i].Y);
        st[a[i].X].pb(i);
        en[a[i].Y].pb(i);
    }
    set<int> cur;
    sort(all(ve));
    for (int u : ve){
        for (int i : st[u]) cur.insert(i);
        for (int i : en[u]) en.erase(i);
        for (int i : en[u]){
            for (int j : cur)
                adj[i].pb(j);
        }
    }
    if (n <= 1000 && q <= 100){
        rep(i,0,q){
            int s,e;
            cin >> s >> e;
            if (s == e){
                cout << 0 << endl;
                continue;
            }
            if (a[s].Y == a[e].Y){
                cout << 1 << endl;
                continue;
            }
            rep(i,1,n+1) par[i] = -1;
            bfs(s);
            if (par[e] == -1) cout << "impossible" << endl;
            else cout << d[e] << endl;
            continue;
        }
    }
    else{
        memset(par,-1,sizeof par);
        rep(i,1,n+1) if (par[i] == -1) bfs(i);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1580 ms 461100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -