Submission #595567

# Submission time Handle Problem Language Result Execution time Memory
595567 2022-07-13T20:25:52 Z Deepesson Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 33804 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 secao[MAX],periodo[MAX];

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);
    }

    if(Q<=100){
        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";
        }
    }else {///Linha
        assert(0);
        int count=0;
        int grupos=0;
        int prox=-1;
        for(int i=0;i!=MAX;++i){
            for(auto&x:add[i]){
                if(i!=prox){
                    ++grupos;
                }
                secao[i]=grupos;
                periodo[i]=count;
                ++count;
                prox=eventos[i].second;
            }
        }
        for(int i=0;i!=Q;++i){
            int a,b;
            std::cin>>a>>b;
            --a;--b;
            if(secao[a]!=secao[b]){
                std::cout<<"impossible\n";
                continue;
            }
            int dist = periodo[a]-periodo[b];
            if(dist<0){
                std::cout<<"impossible\n";
                continue;
            }
            std::cout<<dist<<"\n";
        }
    }
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:103:22: warning: unused variable 'x' [-Wunused-variable]
  103 |             for(auto&x:add[i]){
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11476 KB Output is correct
2 Runtime error 75 ms 33796 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11408 KB Output is correct
2 Correct 8 ms 11444 KB Output is correct
3 Correct 129 ms 11536 KB Output is correct
4 Correct 86 ms 11476 KB Output is correct
5 Correct 90 ms 11540 KB Output is correct
6 Correct 88 ms 11476 KB Output is correct
7 Correct 164 ms 11536 KB Output is correct
8 Correct 180 ms 11540 KB Output is correct
9 Correct 68 ms 11476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11408 KB Output is correct
2 Correct 8 ms 11444 KB Output is correct
3 Correct 129 ms 11536 KB Output is correct
4 Correct 86 ms 11476 KB Output is correct
5 Correct 90 ms 11540 KB Output is correct
6 Correct 88 ms 11476 KB Output is correct
7 Correct 164 ms 11536 KB Output is correct
8 Correct 180 ms 11540 KB Output is correct
9 Correct 68 ms 11476 KB Output is correct
10 Correct 8 ms 11480 KB Output is correct
11 Correct 8 ms 11356 KB Output is correct
12 Correct 118 ms 11532 KB Output is correct
13 Correct 83 ms 11476 KB Output is correct
14 Correct 96 ms 11536 KB Output is correct
15 Correct 87 ms 11476 KB Output is correct
16 Correct 155 ms 11476 KB Output is correct
17 Correct 161 ms 11536 KB Output is correct
18 Correct 73 ms 11596 KB Output is correct
19 Runtime error 16 ms 20128 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11408 KB Output is correct
2 Correct 8 ms 11444 KB Output is correct
3 Correct 129 ms 11536 KB Output is correct
4 Correct 86 ms 11476 KB Output is correct
5 Correct 90 ms 11540 KB Output is correct
6 Correct 88 ms 11476 KB Output is correct
7 Correct 164 ms 11536 KB Output is correct
8 Correct 180 ms 11540 KB Output is correct
9 Correct 68 ms 11476 KB Output is correct
10 Correct 9 ms 11368 KB Output is correct
11 Correct 8 ms 11476 KB Output is correct
12 Correct 125 ms 11476 KB Output is correct
13 Correct 85 ms 11604 KB Output is correct
14 Correct 100 ms 11476 KB Output is correct
15 Correct 92 ms 11536 KB Output is correct
16 Correct 159 ms 11536 KB Output is correct
17 Correct 168 ms 11540 KB Output is correct
18 Correct 74 ms 11544 KB Output is correct
19 Execution timed out 1585 ms 18416 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 83 ms 33804 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11476 KB Output is correct
2 Runtime error 75 ms 33796 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -