Submission #745849

# Submission time Handle Problem Language Result Execution time Memory
745849 2023-05-21T08:47:12 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int>> tav;
vector<vector<int>> g;

main() {
    int N, Q; cin>>N>>Q;
    vector<int> s(N), e(N);
    for(int i=0; i<N; ++i)
    {
        cin>>s[i]>>e[i];
    }
    g.resize(N);
    tav.assign(N, vector<int>(N, INT_MAX/2));
    for(int i=0; i<N; ++i)
    {
        for(int j=0; j<N; ++j)
        {
            if(i!=j && s[j]<=e[i] && e[i]<=e[j]) g[i].push_back(j);
        }
    }

    for(int i=0; i<N; ++i)
    {
        tav[i][i]=0;
        vector<int> volt(N, false);
        queue<int> q;
        q.push(i);
        while(!q.empty())
        {
            int a=q.front();
            q.pop();
            volt[a]=true;
            for(int to:g[a])
            {
                if(volt[to]) continue;
                volt[to]=true;
                q.push(to);
                tav[i][to]=tav[i][a]+1;
            }
        }
    }

    for(int i=0; i<Q; ++i)
    {
        int a, b; cin>>a>>b; a--; b--;
        if(tav[a][b]==INT_MAX/2)
        {
            cout<<"impossible\n";
            continue;
        }
        cout<<tav[a][b]<<'\n';
    }
    
    for(auto x:tav)
    {
        for(auto y:x) cerr<<y<<' ';
        cerr<<endl;
    }
}

Compilation message

events.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 354 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1568 ms 13496 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1568 ms 13496 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1568 ms 13496 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 262 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 354 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -