Submission #721794

# Submission time Handle Problem Language Result Execution time Memory
721794 2023-04-11T07:22:43 Z Mr_Husanboy Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 226268 KB
#include<bits/stdc++.h>
using namespace std;
 
#define all(a) (a).begin(), (a).end()
template<typename T>
int len(T &a){
    return a.size();
}
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
#define ff first
#define ss second

void solve(){
    int n, q; cin >> n >> q;
    vector<pair<int,int>> e(n);
   // map<int,int> mp;
    for(int i = 0; i < n; i ++){
        cin >> e[i].ff >> e[i].ss; 
        //mp[e[i].ff] = 1; mp[e[i].ss] = 1;
    }
    vector<vector<int>> g(n);
    for(int i = 0; i < n; i ++){
        for(int j = 0;j < n; j ++){
            if(i == j) continue;
            if(e[i].ss >= e[j].ff && e[i].ss <= e[j].ss){
                //cout << i + 1 << ' ' << j + 1 << endl;
                g[i].push_back(j);
            }
        }
    }
    vector dis(n, vector(n, 1e9));
    auto bfs = [&](auto &bfs, int i)->void{
        queue<int> q;
        vector<int> used(n);
        q.push(i);
        dis[i][i] = 0;
        used[i] = 1;
        while(!q.empty()){
            int t = q.front();
            q.pop();
            for(auto u : g[t]){
                if(used[u]) continue;
                used[u] = 1;
                dis[i][u] = dis[i][t] + 1;
                q.push(u);
            }
        }
    };
    for(int i = 0; i < n; i ++){
        bfs(bfs, i);
    }
    while(q --){
        int a, b;cin >> a >> b;
        a --; b --;
        if(dis[a][b] == inf){
            cout << "impossible\n";
        }else cout << dis[a][b] << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcases = 1;
    //cin >> testcases;
    while(testcases --){
        solve();
        if(testcases) cout << '\n';
        #ifdef LOCAL
        else cout << '\n';
        cout << "__________________" << endl;
        #endif
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1571 ms 3764 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 20 ms 8176 KB Output is correct
4 Correct 14 ms 8148 KB Output is correct
5 Correct 21 ms 8256 KB Output is correct
6 Correct 56 ms 9000 KB Output is correct
7 Correct 137 ms 9812 KB Output is correct
8 Correct 169 ms 10884 KB Output is correct
9 Correct 857 ms 12244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 20 ms 8176 KB Output is correct
4 Correct 14 ms 8148 KB Output is correct
5 Correct 21 ms 8256 KB Output is correct
6 Correct 56 ms 9000 KB Output is correct
7 Correct 137 ms 9812 KB Output is correct
8 Correct 169 ms 10884 KB Output is correct
9 Correct 857 ms 12244 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 19 ms 8148 KB Output is correct
13 Correct 14 ms 8148 KB Output is correct
14 Correct 20 ms 8148 KB Output is correct
15 Correct 54 ms 9024 KB Output is correct
16 Correct 136 ms 9812 KB Output is correct
17 Correct 172 ms 10956 KB Output is correct
18 Correct 854 ms 12240 KB Output is correct
19 Execution timed out 1561 ms 226268 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 20 ms 8176 KB Output is correct
4 Correct 14 ms 8148 KB Output is correct
5 Correct 21 ms 8256 KB Output is correct
6 Correct 56 ms 9000 KB Output is correct
7 Correct 137 ms 9812 KB Output is correct
8 Correct 169 ms 10884 KB Output is correct
9 Correct 857 ms 12244 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 20 ms 8148 KB Output is correct
13 Correct 15 ms 8148 KB Output is correct
14 Correct 20 ms 8252 KB Output is correct
15 Correct 51 ms 9016 KB Output is correct
16 Correct 139 ms 9824 KB Output is correct
17 Correct 166 ms 10836 KB Output is correct
18 Correct 828 ms 12232 KB Output is correct
19 Execution timed out 1577 ms 3620 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1563 ms 3604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1571 ms 3764 KB Time limit exceeded
3 Halted 0 ms 0 KB -