Submission #1040163

# Submission time Handle Problem Language Result Execution time Memory
1040163 2024-07-31T17:23:27 Z Marco_Escandon Event Hopping (BOI22_events) C++11
10 / 100
1500 ms 43756 KB
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
#define x first
#define y second
#pragma optimize("O3")
vector<vector<ll>> G( 5005);
vector<ll> v[5005];
vector<pair<ll,ll>> input(5005,{0,0});
void cmc(ll n,ll ini)
{
    v[ini].assign(n+1,1e9);
    queue<ll> q;
    q.push(ini);
    v[ini][ini]=0;
    map<ll,ll> mapa;
    mapa[input[ini].y]=1;
    while(!q.empty())
    {
        ll a=q.front();q.pop();
        for(auto i:G[a])
        {
            if(v[ini][i]==1e9)
            {
                v[ini][i]=v[ini][a]+1;
                if(mapa[input[i].y]==0)
                {
                    q.push(i);
                    mapa[input[i].y]=1;
                }
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n,q;
    cin>>n>>q;
    vector<pair<ll,ll>> cad;
    for(int i=1; i<=n; i++)
    {
        ll a,b;
        cin>>a>>b;
        input[i]={a,b};
        cad.push_back({a,i});
        cad.push_back({b,i});
    }
    sort(cad.begin(),cad.end());
    set<ll> s;
    for(int i=0; i<cad.size(); i++)
    {
        vector<ll> temp2;
        ll a=i;
        while(i<cad.size()&&cad[a].x==cad[i].x){
            if(s.find(cad[i].y)!=s.end())
                temp2.push_back(cad[i].y);
            else s.insert(cad[i].y);
            i++;
        }
        i--;
        for(auto j:temp2) for(auto k:s) G[j].push_back(k);
        for(auto j:temp2) if(s.find(j)!=s.end()) s.erase(j);
    }
    for(int i=1; i<=n; i++)
        cmc(n,i);
    for(int i=0; i<q; i++)
    {
        ll a,b;
        cin>>a>>b;
        a=v[a][b];
        if(a==1e9) cout<<"impossible"<<"\n";
        else cout<<a<<"\n";
    }
    return 0;
}

Compilation message

events.cpp:6: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    6 | #pragma optimize("O3")
      | 
events.cpp: In function 'int main()':
events.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0; i<cad.size(); i++)
      |                  ~^~~~~~~~~~~
events.cpp:56:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         while(i<cad.size()&&cad[a].x==cad[i].x){
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Runtime error 4 ms 3032 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 49 ms 4692 KB Output is correct
4 Correct 24 ms 4540 KB Output is correct
5 Correct 44 ms 4692 KB Output is correct
6 Correct 34 ms 5456 KB Output is correct
7 Correct 161 ms 6228 KB Output is correct
8 Correct 171 ms 7248 KB Output is correct
9 Correct 11 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 49 ms 4692 KB Output is correct
4 Correct 24 ms 4540 KB Output is correct
5 Correct 44 ms 4692 KB Output is correct
6 Correct 34 ms 5456 KB Output is correct
7 Correct 161 ms 6228 KB Output is correct
8 Correct 171 ms 7248 KB Output is correct
9 Correct 11 ms 8540 KB Output is correct
10 Correct 0 ms 612 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 40 ms 4668 KB Output is correct
13 Correct 22 ms 4528 KB Output is correct
14 Correct 46 ms 4688 KB Output is correct
15 Correct 33 ms 5468 KB Output is correct
16 Correct 160 ms 6300 KB Output is correct
17 Correct 173 ms 7340 KB Output is correct
18 Correct 12 ms 8536 KB Output is correct
19 Execution timed out 1600 ms 43756 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 49 ms 4692 KB Output is correct
4 Correct 24 ms 4540 KB Output is correct
5 Correct 44 ms 4692 KB Output is correct
6 Correct 34 ms 5456 KB Output is correct
7 Correct 161 ms 6228 KB Output is correct
8 Correct 171 ms 7248 KB Output is correct
9 Correct 11 ms 8540 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 41 ms 4540 KB Output is correct
13 Correct 22 ms 4688 KB Output is correct
14 Correct 45 ms 4660 KB Output is correct
15 Correct 32 ms 5456 KB Output is correct
16 Correct 167 ms 6232 KB Output is correct
17 Correct 174 ms 7156 KB Output is correct
18 Correct 14 ms 8536 KB Output is correct
19 Runtime error 4 ms 3032 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 3032 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Runtime error 4 ms 3032 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -