Submission #877447

# Submission time Handle Problem Language Result Execution time Memory
877447 2023-11-23T08:42:30 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 524288 KB
///#include "art.h"
#include <bits/stdc++.h>

using namespace std;

const long long maxn = 1e5;
const long long mod = 1e9+7;
const long long logn=30;

int main()
{
    ios::sync_with_stdio(false);
    long long n,q;
    cin>>n>>q;
    vector<pair<long long,long long>>v;
    for(long long i=0;i<n;i++)
    {
        long long x,y;
        cin>>x>>y;
        v.push_back({x,y});
    }
    vector<long long>g[n];
    for(long long i=0;i<n;i++)
    {
        for(long long j=0;j<n;j++)
        {
            if(j==i)continue;
            if(v[j].first<=v[i].second)
            {
                if(v[j].second>=v[i].second)
                {
                    g[i].push_back(j);
                }
            }
        }
    }
    /*if(n<1005)
    {
        while(q--)
        {
            long long ans=-1;
            long long l,r;
            cin>>l>>r;
            l--;r--;
            bool vis[n];
            memset(vis,0,sizeof vis);
            queue<long long>Q;
            Q.push(l);
            Q.push(0);
            vis[l]=true;
            while(!Q.empty())
            {
                long long teme=Q.front();
                Q.pop();
                long long k=Q.front();Q.pop();
                if(teme==r)
                {
                    ans=k;
                    break;
                }
                for(auto ax:g[teme])
                {
                    if(vis[ax])continue;
                    Q.push(ax);
                    Q.push(k+1);
                    vis[ax]=true;
                }
            }
            if(ans==-1)
            {
                cout<<"impossible"<<endl;
            }
            else
            {
                cout<<ans<<endl;
            }
        }
        return 0;
    }*/
    long long dis[n][n];
    for(long long i=0;i<n;i++)
    {
        for(long long j=0;j<n;j++)
        {
            dis[i][j]=2e9;
        }
    }
    for(long long i=0;i<n;i++)
    {
            dis[i][i]=0;
            queue<long long>Q;
            Q.push(i);
            Q.push(0);
            Q.push(-1);
            while(!Q.empty())
            {
                long long teme=Q.front();
                Q.pop();
                long long k=Q.front();Q.pop();
                long long prev=Q.front();Q.pop();
                if(teme!=i)
                {
                    dis[i][teme]=min(dis[i][teme], k);
                }
                for(auto ax:g[teme])
                {
                    if(prev==ax)continue;
                    Q.push(ax);
                    Q.push(k+1);
                    Q.push(teme);
                }
            }
    }
    while(q--)
    {
        long long l,r;
        cin>>l>>r;
        l--;r--;
        if(dis[l][r]==2e9)
        {
            cout<<"impossible"<<endl;
        }
        else
        {
            cout<<dis[l][r]<<endl;
        }
    }
    return 0;
}


/*
void solve(long long n)
{
    if(n<=6)
    {
        vector<long long>v;
        for(long long i=1;i<=n;i++)
        {
            v.push_back(i);
        }
        do
        {
            long long kol=publish(v);
            if(kol==0)
            {
                answer(v);
            }
        }while(next_permutation(v.begin(),v.end()));
    }


   /// publish(order);
   /// answer(order);
}

*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1573 ms 5876 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 14 ms 8124 KB Output is correct
4 Correct 11 ms 8284 KB Output is correct
5 Correct 19 ms 8284 KB Output is correct
6 Runtime error 367 ms 524288 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 14 ms 8124 KB Output is correct
4 Correct 11 ms 8284 KB Output is correct
5 Correct 19 ms 8284 KB Output is correct
6 Runtime error 367 ms 524288 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 14 ms 8124 KB Output is correct
4 Correct 11 ms 8284 KB Output is correct
5 Correct 19 ms 8284 KB Output is correct
6 Runtime error 367 ms 524288 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1512 ms 5836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1573 ms 5876 KB Time limit exceeded
3 Halted 0 ms 0 KB -