답안 #604331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604331 2022-07-25T04:14:47 Z Plurm Event Hopping (BOI22_events) C++11
0 / 100
1500 ms 50464 KB
#include <bits/stdc++.h>
using namespace std;

short 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});
  }
  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 = 0; v < n; v++) {
        if (u == v)
          continue;
        if (events[v].first <= events[u].second &&
            events[u].second <= events[v].second) {
          if (dist[i][v] > n) {
            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] > 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:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%d%d", &n, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~
events.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d%d", &s, &e);
      |     ~~~~~^~~~~~~~~~~~~~~~
events.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d%d", &s, &e);
      |     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49220 KB Output is correct
2 Execution timed out 1577 ms 50464 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49236 KB Output is correct
2 Correct 18 ms 49212 KB Output is correct
3 Execution timed out 1576 ms 49312 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49236 KB Output is correct
2 Correct 18 ms 49212 KB Output is correct
3 Execution timed out 1576 ms 49312 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49236 KB Output is correct
2 Correct 18 ms 49212 KB Output is correct
3 Execution timed out 1576 ms 49312 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1582 ms 50392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49220 KB Output is correct
2 Execution timed out 1577 ms 50464 KB Time limit exceeded
3 Halted 0 ms 0 KB -