답안 #895375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895375 2023-12-29T20:04:33 Z MilosMilutinovic 버스 (JOI14_bus) C++14
100 / 100
133 ms 23888 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<array<int, 3>>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v, x, y;
    cin >> u >> v >> x >> y;
    --u; --v;
    g[u].push_back({v, x, y});
  }
  vector<int> ptr(n);
  for (int i = 0; i < n; i++) {
    sort(g[i].begin(), g[i].end(), [&](array<int, 3> a, array<int, 3> b) {
      return a[1] > b[1];
    });
  }
  const int inf = (int) 1e9;
  vector<int> d(n, inf);
  function<void(int, int)> Update = [&](int v, int t) {
    d[v] = min(d[v], t);
    vector<pair<int, int>> e;
    while (ptr[v] < (int) g[v].size() && g[v][ptr[v]][1] >= d[v]) {
      e.emplace_back(g[v][ptr[v]][2], g[v][ptr[v]][0]);
      ptr[v] += 1;
    }
    sort(e.begin(), e.end());
    for (auto& p : e) {
      Update(p.second, p.first);
    }
  };
  vector<pair<int, int>> v;
  for (auto& p : g[0]) {
    Update(p[0], p[2]);
    v.emplace_back(d[n - 1], p[1]);
  }
  sort(v.begin(), v.end());
  int k = (int) v.size();
  vector<int> mx(k);
  for (int i = 0; i < k; i++) {
    if (i > 0) {
      mx[i] = mx[i - 1];
    }
    mx[i] = max(mx[i], v[i].second);
  }
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (v.empty() || v[0].first > t) {
      cout << -1 << '\n';
      continue;
    }
    int low = 0, high = k - 1, p = 0;
    while (low <= high) {
      int mid = low + high >> 1;
      if (v[mid].first <= t) {
        p = mid;
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    cout << mx[p] << '\n';
  }
  return 0;
}

Compilation message

bus.cpp: In function 'int main()':
bus.cpp:62:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |       int mid = low + high >> 1;
      |                 ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 16 ms 1884 KB Output is correct
3 Correct 16 ms 1884 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 11 ms 860 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 12 ms 1116 KB Output is correct
10 Correct 16 ms 2140 KB Output is correct
11 Correct 14 ms 1372 KB Output is correct
12 Correct 18 ms 2312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 18164 KB Output is correct
2 Correct 101 ms 18268 KB Output is correct
3 Correct 101 ms 18276 KB Output is correct
4 Correct 102 ms 18456 KB Output is correct
5 Correct 102 ms 18220 KB Output is correct
6 Correct 102 ms 18252 KB Output is correct
7 Correct 95 ms 14708 KB Output is correct
8 Correct 133 ms 18324 KB Output is correct
9 Correct 117 ms 18308 KB Output is correct
10 Correct 94 ms 14052 KB Output is correct
11 Correct 96 ms 14164 KB Output is correct
12 Correct 92 ms 14208 KB Output is correct
13 Correct 92 ms 14164 KB Output is correct
14 Correct 92 ms 14184 KB Output is correct
15 Correct 92 ms 14200 KB Output is correct
16 Correct 51 ms 23120 KB Output is correct
17 Correct 46 ms 23000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 19540 KB Output is correct
2 Correct 117 ms 19280 KB Output is correct
3 Correct 116 ms 19844 KB Output is correct
4 Correct 115 ms 19780 KB Output is correct
5 Correct 114 ms 19336 KB Output is correct
6 Correct 116 ms 19540 KB Output is correct
7 Correct 114 ms 16524 KB Output is correct
8 Correct 116 ms 19792 KB Output is correct
9 Correct 113 ms 19788 KB Output is correct
10 Correct 113 ms 15696 KB Output is correct
11 Correct 109 ms 15844 KB Output is correct
12 Correct 129 ms 15876 KB Output is correct
13 Correct 110 ms 16072 KB Output is correct
14 Correct 109 ms 15700 KB Output is correct
15 Correct 108 ms 15696 KB Output is correct
16 Correct 58 ms 23888 KB Output is correct