Submission #842207

# Submission time Handle Problem Language Result Execution time Memory
842207 2023-09-02T14:33:59 Z d4xn Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 22740 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5;

int n, q;
pair<int, int> sg[N];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    sg[i] = make_pair(l, r);
  }

  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;

    int z = -1;
    vector<bool> vis(n, 0);
    queue<pair<int, int>> qu;
    qu.push(make_pair(0, x));
    while (!qu.empty()) {
      int d = qu.front().first;
      int u = qu.front().second;
      qu.pop();

      if (vis[u]) continue;
      vis[u] = 1;

      if (u == y) {
        z = d;
        break;
      }

      for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        if (sg[i].first <= sg[u].second && sg[u].second <= sg[i].second) {
          qu.push(make_pair(d+1, i));
        }
      }
    }

    if (z == -1) cout << "impossible\n";
    else cout << z << "\n";
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 1587 ms 1080 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 150 ms 448 KB Output is correct
4 Correct 33 ms 348 KB Output is correct
5 Correct 59 ms 348 KB Output is correct
6 Correct 65 ms 604 KB Output is correct
7 Correct 135 ms 1564 KB Output is correct
8 Correct 116 ms 2280 KB Output is correct
9 Correct 381 ms 3468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 150 ms 448 KB Output is correct
4 Correct 33 ms 348 KB Output is correct
5 Correct 59 ms 348 KB Output is correct
6 Correct 65 ms 604 KB Output is correct
7 Correct 135 ms 1564 KB Output is correct
8 Correct 116 ms 2280 KB Output is correct
9 Correct 381 ms 3468 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 147 ms 348 KB Output is correct
13 Correct 33 ms 480 KB Output is correct
14 Correct 64 ms 460 KB Output is correct
15 Correct 63 ms 604 KB Output is correct
16 Correct 130 ms 1572 KB Output is correct
17 Correct 117 ms 2440 KB Output is correct
18 Correct 362 ms 3632 KB Output is correct
19 Execution timed out 1550 ms 22740 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 150 ms 448 KB Output is correct
4 Correct 33 ms 348 KB Output is correct
5 Correct 59 ms 348 KB Output is correct
6 Correct 65 ms 604 KB Output is correct
7 Correct 135 ms 1564 KB Output is correct
8 Correct 116 ms 2280 KB Output is correct
9 Correct 381 ms 3468 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 504 KB Output is correct
12 Correct 151 ms 344 KB Output is correct
13 Correct 33 ms 348 KB Output is correct
14 Correct 60 ms 460 KB Output is correct
15 Correct 64 ms 604 KB Output is correct
16 Correct 132 ms 1616 KB Output is correct
17 Correct 117 ms 2528 KB Output is correct
18 Correct 359 ms 3448 KB Output is correct
19 Execution timed out 1507 ms 2412 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1552 ms 1116 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 1587 ms 1080 KB Time limit exceeded
3 Halted 0 ms 0 KB -