Submission #896391

# Submission time Handle Problem Language Result Execution time Memory
896391 2024-01-01T11:04:49 Z karamkallasi Event Hopping (BOI22_events) C++14
10 / 100
1500 ms 109168 KB
#include <bits/stdc++.h>
#define T ll tt ; cin>>tt ; while(tt--)
#define fast ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define endl '\n'
#define yes void (cout << "YES" << endl)
#define no void (cout << "NO" << endl)
#define pb push_back
#define F first
#define S second
#define ld long double
#define fixed(g) fixed<<setprecision(g)
#define ll long long
using namespace std;
const ll N = 2e6 + 9 ;
const ll oo = 1e18 + 7 ;
ll n , m , k , x , y , z , ind , ans , a[N] , b[N] , mn , sz[N] ;
bool vis[N] , ff ;
vector<ll>v[N];

void bfs(ll x , ll y){
    for(ll i=1 ; i<=n ; i++){
        vis[i] = 0 ;
        sz[i] = 0 ;
    }
    ff = 0 , ans = -1 ;
    queue<ll> q ;
    q.push(x);
    while(!q.empty()){
       ll node = q.front() ;
       q.pop() ;
       vis[node] = 1 ;
      //  cout<<node<<'&'<<sz[node]<<' '<<vis[4]<<endl ;
       for(auto e : v[node]){
            if(vis[e])continue ;
            vis[e] = 1 ;
            sz[e] = sz[node] + 1 ;
            if(e==y){
                ans = sz[e] ;
                ff = 1 ;
                break ;
            }
            q.push(e);
       }
       if(ff)break ;
    }
}
int main(){
fast
    cin >> n >> m ;
    for(ll i=1 ; i<=n ; i++){
        cin >> a[i] >> b[i] ;
    }
    for(ll i=1 ; i<=n ; i++){
        for(ll j=1 ; j<=n ; j++){
            if(i==j)continue ;
            if(a[j]<=b[i] && b[i]<=b[j])
                v[i].pb(j);
        }
    }
    while(m--){
        cin >> x >> y ;
        if(x==y)cout<<0<<endl;
        else{
            bfs(x , y) ;
            if(ans==-1)cout<<"impossible"<<endl ;
            else cout<<ans<<endl ;
        }
    }

    return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 53852 KB Output is correct
2 Execution timed out 1555 ms 54416 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 53852 KB Output is correct
2 Correct 13 ms 53852 KB Output is correct
3 Correct 17 ms 54048 KB Output is correct
4 Correct 17 ms 53992 KB Output is correct
5 Correct 17 ms 53852 KB Output is correct
6 Correct 19 ms 55396 KB Output is correct
7 Correct 23 ms 57176 KB Output is correct
8 Correct 22 ms 59228 KB Output is correct
9 Correct 21 ms 62044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 53852 KB Output is correct
2 Correct 13 ms 53852 KB Output is correct
3 Correct 17 ms 54048 KB Output is correct
4 Correct 17 ms 53992 KB Output is correct
5 Correct 17 ms 53852 KB Output is correct
6 Correct 19 ms 55396 KB Output is correct
7 Correct 23 ms 57176 KB Output is correct
8 Correct 22 ms 59228 KB Output is correct
9 Correct 21 ms 62044 KB Output is correct
10 Correct 12 ms 54108 KB Output is correct
11 Correct 12 ms 53852 KB Output is correct
12 Correct 16 ms 54044 KB Output is correct
13 Correct 15 ms 53868 KB Output is correct
14 Correct 16 ms 53852 KB Output is correct
15 Correct 20 ms 55616 KB Output is correct
16 Correct 22 ms 57180 KB Output is correct
17 Correct 23 ms 59224 KB Output is correct
18 Correct 20 ms 62044 KB Output is correct
19 Execution timed out 1538 ms 109168 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 53852 KB Output is correct
2 Correct 13 ms 53852 KB Output is correct
3 Correct 17 ms 54048 KB Output is correct
4 Correct 17 ms 53992 KB Output is correct
5 Correct 17 ms 53852 KB Output is correct
6 Correct 19 ms 55396 KB Output is correct
7 Correct 23 ms 57176 KB Output is correct
8 Correct 22 ms 59228 KB Output is correct
9 Correct 21 ms 62044 KB Output is correct
10 Correct 13 ms 53848 KB Output is correct
11 Correct 12 ms 53888 KB Output is correct
12 Correct 18 ms 53848 KB Output is correct
13 Correct 18 ms 54116 KB Output is correct
14 Correct 17 ms 53852 KB Output is correct
15 Correct 22 ms 55408 KB Output is correct
16 Correct 21 ms 57180 KB Output is correct
17 Correct 25 ms 59224 KB Output is correct
18 Correct 23 ms 62044 KB Output is correct
19 Execution timed out 1540 ms 54212 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1537 ms 52180 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 53852 KB Output is correct
2 Execution timed out 1555 ms 54416 KB Time limit exceeded
3 Halted 0 ms 0 KB -