Submission #604317

# Submission time Handle Problem Language Result Execution time Memory
604317 2022-07-25T04:02:49 Z Plurm Event Hopping (BOI22_events) C++11
10 / 100
1500 ms 130596 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> g[100005];
int dist[5005][5005];
int main() {
  memset(dist, 0x3F, sizeof(dist));
  int n, q;
  scanf("%d%d", &n, &q);
  vector<pair<int, int>> events;
  for (int i = 1; i <= n; i++) {
    int s, e;
    scanf("%d%d", &s, &e);
    events.push_back({s, e});
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      if (events[j].first <= events[i].second &&
          events[i].second <= events[j].second)
        g[i].push_back(j);
    }
  }
  queue<int> pq;
  for (int i = 0; i < n; i++) {
    dist[i][i] = 0;
    pq.push(i);
    while (!pq.empty()) {
      int u = pq.front();
      pq.pop();
      for (int v : g[u]) {
        if (dist[i][v] > dist[i][u] + 1) {
          dist[i][v] = dist[i][u] + 1;
          pq.push(v);
        }
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int s, e;
    scanf("%d%d", &s, &e);
    if (dist[s - 1][e - 1] > 1e9)
      printf("impossible\n");
    else
      printf("%d\n", dist[s - 1][e - 1]);
    // can e be reached by s?, if yes, what is the shortest path?
  }
  return 0;
}

Compilation message

events.cpp: In function 'int main()':
events.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   scanf("%d%d", &n, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~
events.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d%d", &s, &e);
      |     ~~~~~^~~~~~~~~~~~~~~~
events.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d%d", &s, &e);
      |     ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 100556 KB Output is correct
2 Execution timed out 1590 ms 103704 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 100684 KB Output is correct
2 Correct 35 ms 100552 KB Output is correct
3 Correct 49 ms 100724 KB Output is correct
4 Correct 48 ms 100632 KB Output is correct
5 Correct 54 ms 100672 KB Output is correct
6 Correct 92 ms 101496 KB Output is correct
7 Correct 209 ms 102316 KB Output is correct
8 Correct 242 ms 103368 KB Output is correct
9 Correct 1247 ms 104780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 100684 KB Output is correct
2 Correct 35 ms 100552 KB Output is correct
3 Correct 49 ms 100724 KB Output is correct
4 Correct 48 ms 100632 KB Output is correct
5 Correct 54 ms 100672 KB Output is correct
6 Correct 92 ms 101496 KB Output is correct
7 Correct 209 ms 102316 KB Output is correct
8 Correct 242 ms 103368 KB Output is correct
9 Correct 1247 ms 104780 KB Output is correct
10 Correct 36 ms 100556 KB Output is correct
11 Correct 36 ms 100664 KB Output is correct
12 Correct 57 ms 100708 KB Output is correct
13 Correct 45 ms 100692 KB Output is correct
14 Correct 51 ms 100668 KB Output is correct
15 Correct 105 ms 101424 KB Output is correct
16 Correct 219 ms 102348 KB Output is correct
17 Correct 243 ms 103256 KB Output is correct
18 Correct 1275 ms 104716 KB Output is correct
19 Execution timed out 1596 ms 130596 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 100684 KB Output is correct
2 Correct 35 ms 100552 KB Output is correct
3 Correct 49 ms 100724 KB Output is correct
4 Correct 48 ms 100632 KB Output is correct
5 Correct 54 ms 100672 KB Output is correct
6 Correct 92 ms 101496 KB Output is correct
7 Correct 209 ms 102316 KB Output is correct
8 Correct 242 ms 103368 KB Output is correct
9 Correct 1247 ms 104780 KB Output is correct
10 Correct 40 ms 100648 KB Output is correct
11 Correct 37 ms 100660 KB Output is correct
12 Correct 50 ms 100728 KB Output is correct
13 Correct 46 ms 100716 KB Output is correct
14 Correct 52 ms 100692 KB Output is correct
15 Correct 93 ms 101452 KB Output is correct
16 Correct 220 ms 102316 KB Output is correct
17 Correct 296 ms 103368 KB Output is correct
18 Correct 1424 ms 104712 KB Output is correct
19 Execution timed out 1584 ms 103508 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1601 ms 101768 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 100556 KB Output is correct
2 Execution timed out 1590 ms 103704 KB Time limit exceeded
3 Halted 0 ms 0 KB -