Submission #612465

# Submission time Handle Problem Language Result Execution time Memory
612465 2022-07-29T15:29:37 Z Plurm Event Hopping (BOI22_events) C++11
0 / 100
1500 ms 58240 KB
#include <bits/stdc++.h>
using namespace std;

vector<short> g[100005];
vector<short> rg[100005];
short dist[5005][5005];
short fastqueue[8 * 1048576];
int hidx = 0;
int tidx = 0;
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++) {
    vector<int> tmp;
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      if (events[j].first <= events[i].second &&
          events[i].second <= events[j].second) {
        rg[i].push_back((short)j);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    map<int, int> mp;
    for (short j : rg[i]) {
      int hsh = 0;
      for (short k : rg[j]) {
        hsh *= 53;
        hsh += k;
      }
      mp[hsh] = j;
    }
    for (auto p : mp) {
      g[i].push_back(p.second);
    }
  }
  for (int i = 0; i < n; i++) {
    dist[i][i] = 0;
    fastqueue[tidx++] = i;
    while (hidx != tidx) {
      short u = fastqueue[hidx++];
      for (short v : g[u]) {
        if (dist[i][v] > dist[i][u] + 1) {
          dist[i][v] = dist[i][u] + 1;
          fastqueue[tidx++] = v;
        }
      }
    }
  }
  for (int i = 0; i < q; i++) {
    int s, e;
    scanf("%d%d", &s, &e);
    if (dist[s - 1][e - 1] > n)
      printf("impossible\n");
    else
      printf("%hd\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:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d%d", &n, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~
events.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d%d", &s, &e);
      |     ~~~~~^~~~~~~~~~~~~~~~
events.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |     scanf("%d%d", &s, &e);
      |     ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 53988 KB Output is correct
2 Execution timed out 1560 ms 55416 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 53992 KB Output is correct
2 Correct 23 ms 53968 KB Output is correct
3 Correct 34 ms 55080 KB Output is correct
4 Correct 31 ms 54532 KB Output is correct
5 Correct 35 ms 55072 KB Output is correct
6 Correct 134 ms 55428 KB Output is correct
7 Correct 345 ms 56688 KB Output is correct
8 Correct 555 ms 57624 KB Output is correct
9 Execution timed out 1570 ms 58240 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 53992 KB Output is correct
2 Correct 23 ms 53968 KB Output is correct
3 Correct 34 ms 55080 KB Output is correct
4 Correct 31 ms 54532 KB Output is correct
5 Correct 35 ms 55072 KB Output is correct
6 Correct 134 ms 55428 KB Output is correct
7 Correct 345 ms 56688 KB Output is correct
8 Correct 555 ms 57624 KB Output is correct
9 Execution timed out 1570 ms 58240 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 53992 KB Output is correct
2 Correct 23 ms 53968 KB Output is correct
3 Correct 34 ms 55080 KB Output is correct
4 Correct 31 ms 54532 KB Output is correct
5 Correct 35 ms 55072 KB Output is correct
6 Correct 134 ms 55428 KB Output is correct
7 Correct 345 ms 56688 KB Output is correct
8 Correct 555 ms 57624 KB Output is correct
9 Execution timed out 1570 ms 58240 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1569 ms 55376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 53988 KB Output is correct
2 Execution timed out 1560 ms 55416 KB Time limit exceeded
3 Halted 0 ms 0 KB -