Submission #721792

# Submission time Handle Problem Language Result Execution time Memory
721792 2023-04-11T07:21:04 Z Mr_Husanboy Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 226900 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;
    }
    map<int,int> id;
    for(auto [a,b] : mp){
        id[a] = len(id);
    }
    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 = [&](int i){
        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(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 1 ms 212 KB Output is correct
2 Execution timed out 1575 ms 13068 KB Time limit exceeded
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 Correct 21 ms 8276 KB Output is correct
4 Correct 16 ms 8284 KB Output is correct
5 Correct 22 ms 8348 KB Output is correct
6 Correct 59 ms 9084 KB Output is correct
7 Correct 168 ms 10004 KB Output is correct
8 Correct 169 ms 11072 KB Output is correct
9 Correct 888 ms 12244 KB Output is correct
# 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 Correct 21 ms 8276 KB Output is correct
4 Correct 16 ms 8284 KB Output is correct
5 Correct 22 ms 8348 KB Output is correct
6 Correct 59 ms 9084 KB Output is correct
7 Correct 168 ms 10004 KB Output is correct
8 Correct 169 ms 11072 KB Output is correct
9 Correct 888 ms 12244 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 21 ms 8276 KB Output is correct
13 Correct 15 ms 8292 KB Output is correct
14 Correct 26 ms 8340 KB Output is correct
15 Correct 53 ms 9044 KB Output is correct
16 Correct 143 ms 10012 KB Output is correct
17 Correct 166 ms 11072 KB Output is correct
18 Correct 978 ms 12244 KB Output is correct
19 Execution timed out 1582 ms 226900 KB Time limit exceeded
20 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 Correct 21 ms 8276 KB Output is correct
4 Correct 16 ms 8284 KB Output is correct
5 Correct 22 ms 8348 KB Output is correct
6 Correct 59 ms 9084 KB Output is correct
7 Correct 168 ms 10004 KB Output is correct
8 Correct 169 ms 11072 KB Output is correct
9 Correct 888 ms 12244 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 20 ms 8268 KB Output is correct
13 Correct 14 ms 8276 KB Output is correct
14 Correct 23 ms 8352 KB Output is correct
15 Correct 57 ms 9044 KB Output is correct
16 Correct 151 ms 10016 KB Output is correct
17 Correct 161 ms 11092 KB Output is correct
18 Correct 898 ms 12244 KB Output is correct
19 Execution timed out 1572 ms 13028 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1552 ms 13392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1575 ms 13068 KB Time limit exceeded
3 Halted 0 ms 0 KB -