답안 #604345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604345 2022-07-25T04:25:53 Z Plurm Event Hopping (BOI22_events) C++11
0 / 100
1500 ms 101848 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++) {
    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) {
        tmp.push_back(j);
      }
    }
    sort(tmp.begin(), tmp.end(), [&events](int i, int j) {
      return events[i].second > events[j].second;
    });
    for (int j = 0; j < min((int)tmp.size(), 10); j++) {
      g[i].push_back(tmp[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:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     scanf("%d%d", &s, &e);
      |     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 100644 KB Output is correct
2 Execution timed out 1586 ms 101848 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 100712 KB Output is correct
2 Correct 36 ms 100596 KB Output is correct
3 Correct 55 ms 100712 KB Output is correct
4 Correct 49 ms 100708 KB Output is correct
5 Correct 51 ms 100712 KB Output is correct
6 Incorrect 48 ms 100672 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 100712 KB Output is correct
2 Correct 36 ms 100596 KB Output is correct
3 Correct 55 ms 100712 KB Output is correct
4 Correct 49 ms 100708 KB Output is correct
5 Correct 51 ms 100712 KB Output is correct
6 Incorrect 48 ms 100672 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 100712 KB Output is correct
2 Correct 36 ms 100596 KB Output is correct
3 Correct 55 ms 100712 KB Output is correct
4 Correct 49 ms 100708 KB Output is correct
5 Correct 51 ms 100712 KB Output is correct
6 Incorrect 48 ms 100672 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1582 ms 101784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 100644 KB Output is correct
2 Execution timed out 1586 ms 101848 KB Time limit exceeded
3 Halted 0 ms 0 KB -