답안 #595551

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595551 2022-07-13T20:16:02 Z Deepesson Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 5848 KB
#include <bits/stdc++.h>
#define MAX 10005
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];
std::map<int,bool> moscando;
std::map<int,int> visitado;

void explora(int x){
    for(auto&x:catalogo_avanco)x=0;
    moscando.clear();
    visitado.clear();
    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(auto&x:moscando){
                if(!x.second)continue;
                if(d){
                    if(!visitado[x.first])
                        visitado[x.first]=d+1;
                    else visitado[x.first]=std::min(visitado[x.first],d+1);
                }
               // std::cout<<"Visita "<<x.first<<" "<<d<<" "<<i<<"\n";
                if(!catalogo_avanco[eventos[x.first].second])catalogo_avanco[eventos[x.first].second]=d+1;
                else
                catalogo_avanco[eventos[x.first].second]=std::min((int)catalogo_avanco[eventos[x.first].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";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Runtime error 41 ms 5732 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 488 ms 996 KB Output is correct
4 Correct 143 ms 960 KB Output is correct
5 Correct 323 ms 980 KB Output is correct
6 Correct 186 ms 924 KB Output is correct
7 Execution timed out 1589 ms 972 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 488 ms 996 KB Output is correct
4 Correct 143 ms 960 KB Output is correct
5 Correct 323 ms 980 KB Output is correct
6 Correct 186 ms 924 KB Output is correct
7 Execution timed out 1589 ms 972 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 488 ms 996 KB Output is correct
4 Correct 143 ms 960 KB Output is correct
5 Correct 323 ms 980 KB Output is correct
6 Correct 186 ms 924 KB Output is correct
7 Execution timed out 1589 ms 972 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 5848 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Runtime error 41 ms 5732 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -