Submission #595559

# Submission time Handle Problem Language Result Execution time Memory
595559 2022-07-13T20:19:23 Z Deepesson Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 18792 KB
#include <bits/stdc++.h>
#define MAX 200005
int N,Q;
typedef std::pair<int,int> pii;
std::vector<pii> eventos;

std::vector<int> add[MAX];

std::vector<int> rem[MAX];

int catalogo_avanco[MAX];
bool moscando[MAX];
int visitado[MAX];

void explora(int x){
    memset(&catalogo_avanco,0,sizeof(catalogo_avanco));
    memset(&visitado,0,sizeof(visitado));
    memset(&moscando,0,sizeof(moscando));
    catalogo_avanco[eventos[x].second]=1;
    for(int i=0;i!=MAX;++i){
        for(auto&x:add[i]){
            moscando[x]=true;
        }
        int d = catalogo_avanco[i];
        if(d){
            for(int i=0;i!=N;++i){
                auto& x = moscando[i];
                if(!x)continue;
                if(d){
                    if(!visitado[i])
                        visitado[i]=d+1;
                    else visitado[i]=std::min(visitado[i],d+1);
                }
               // std::cout<<"Visita "<<x.first<<" "<<d<<" "<<i<<"\n";
                if(!catalogo_avanco[eventos[i].second])catalogo_avanco[eventos[i].second]=d+1;
                else
                catalogo_avanco[eventos[i].second]=std::min((int)catalogo_avanco[eventos[i].second],d+1);
            }
        }
        for(auto&x:rem[i]){
            moscando[x]=false;
        }
    }

}

typedef std::pair<int,int*> pipo;

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    std::cin>>N>>Q;
    for(int i=0;i!=N;++i){
        int a,b;
        std::cin>>a>>b;
        eventos.push_back({a,b});
    }

    {
        std::vector<pipo> comprime;
        for(auto&x:eventos){
            comprime.push_back({x.first,&x.first});
            comprime.push_back({x.second,&x.second});
        }
        std::sort(comprime.begin(),comprime.end());
        int last=-1,cord=1;
        for(auto&x:comprime){
            if(x.first!=last){
                last=x.first;
                ++cord;
            }
            *x.second=cord;
        }
    }
    for(int i=0;i!=N;++i){
        add[eventos[i].first].push_back(i);
        rem[eventos[i].second].push_back(i);
    }
    for(int i=0;i!=Q;++i){
        int s,e;
        std::cin>>s>>e;--s;--e;
        if(s==e){
            std::cout<<"0\n";
            continue;
        }
        explora(s);
        if(visitado[e]){
            std::cout<<visitado[e]-1<<"\n";
        }else std::cout<<"impossible\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11348 KB Output is correct
2 Execution timed out 1568 ms 18752 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11348 KB Output is correct
2 Correct 8 ms 11348 KB Output is correct
3 Correct 124 ms 11544 KB Output is correct
4 Correct 98 ms 11536 KB Output is correct
5 Correct 101 ms 11476 KB Output is correct
6 Correct 82 ms 11540 KB Output is correct
7 Correct 155 ms 11544 KB Output is correct
8 Correct 173 ms 11544 KB Output is correct
9 Correct 69 ms 11436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11348 KB Output is correct
2 Correct 8 ms 11348 KB Output is correct
3 Correct 124 ms 11544 KB Output is correct
4 Correct 98 ms 11536 KB Output is correct
5 Correct 101 ms 11476 KB Output is correct
6 Correct 82 ms 11540 KB Output is correct
7 Correct 155 ms 11544 KB Output is correct
8 Correct 173 ms 11544 KB Output is correct
9 Correct 69 ms 11436 KB Output is correct
10 Correct 7 ms 11476 KB Output is correct
11 Correct 8 ms 11440 KB Output is correct
12 Correct 125 ms 11540 KB Output is correct
13 Correct 83 ms 11544 KB Output is correct
14 Correct 98 ms 11676 KB Output is correct
15 Correct 85 ms 11544 KB Output is correct
16 Correct 167 ms 11544 KB Output is correct
17 Correct 151 ms 11540 KB Output is correct
18 Correct 67 ms 11476 KB Output is correct
19 Execution timed out 1590 ms 11824 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11348 KB Output is correct
2 Correct 8 ms 11348 KB Output is correct
3 Correct 124 ms 11544 KB Output is correct
4 Correct 98 ms 11536 KB Output is correct
5 Correct 101 ms 11476 KB Output is correct
6 Correct 82 ms 11540 KB Output is correct
7 Correct 155 ms 11544 KB Output is correct
8 Correct 173 ms 11544 KB Output is correct
9 Correct 69 ms 11436 KB Output is correct
10 Correct 7 ms 11348 KB Output is correct
11 Correct 8 ms 11348 KB Output is correct
12 Correct 121 ms 11544 KB Output is correct
13 Correct 88 ms 11548 KB Output is correct
14 Correct 101 ms 11532 KB Output is correct
15 Correct 93 ms 11540 KB Output is correct
16 Correct 153 ms 11476 KB Output is correct
17 Correct 156 ms 11544 KB Output is correct
18 Correct 68 ms 11536 KB Output is correct
19 Execution timed out 1543 ms 18792 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1584 ms 18692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11348 KB Output is correct
2 Execution timed out 1568 ms 18752 KB Time limit exceeded
3 Halted 0 ms 0 KB -