Submission #50732989


Source Code Expand

#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using int64 = long long;
using uint = unsigned int;
using uint64 = unsigned long long;
bool ckmin(auto& a, auto b) { return b < a ? a = b, 1 : 0; }
bool ckmax(auto& a, auto b) { return b > a ? a = b, 1 : 0; }
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;
  vector<uint64> l(m), d(m), k(m), c(m), A(m), B(m);
  vector go(n, vector<int>());
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> d[i] >> k[i] >> c[i] >> A[i] >> B[i];
    A[i]--, B[i]--;
    go[B[i]].push_back({i});
  }

  vector<uint64> dist(n);
  dist[n - 1] = numeric_limits<uint64>::max();
  priority_queue<pair<uint64, int>> que;
  que.push({dist[n - 1], n - 1});
  vector<bool> vt(n);
  while (!que.empty()) {
    auto [_, u] = que.top();
    que.pop();
    if (vt[u]) continue;
    vt[u] = true;
    for (int i : go[u]) {
      if (dist[u] < c[i]) continue;
      uint64 v = A[i];
      uint64 t = dist[u] - c[i];
      if (t >= l[i]) {
        uint64 x = (t - l[i]) / d[i];
        ckmin(x, k[i] - 1);
        if (l[i] + x * d[i] > dist[v]) {
          dist[v] = l[i] + x * d[i];
          que.push({dist[v], v});
        }
      }
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (vt[i]) cout << dist[i] << '\n';
    else cout << "Unreachable\n";
  }

  return 0;
}

Submission Info

Submission Time
Task E - Last Train
User xindubawukong
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1457 Byte
Status AC
Exec Time 141 ms
Memory 24440 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3400 KiB
00_sample_01.txt AC 1 ms 3544 KiB
00_sample_02.txt AC 1 ms 3564 KiB
01_random_03.txt AC 138 ms 24428 KiB
01_random_04.txt AC 141 ms 24436 KiB
01_random_05.txt AC 132 ms 24440 KiB
01_random_06.txt AC 134 ms 24372 KiB
01_random_07.txt AC 131 ms 24376 KiB
01_random_08.txt AC 112 ms 23624 KiB
01_random_09.txt AC 113 ms 23612 KiB
01_random_10.txt AC 88 ms 22720 KiB
01_random_11.txt AC 72 ms 13900 KiB
01_random_12.txt AC 116 ms 20272 KiB
01_random_13.txt AC 49 ms 11304 KiB
01_random_14.txt AC 22 ms 7776 KiB
01_random_15.txt AC 21 ms 6732 KiB
01_random_16.txt AC 36 ms 13324 KiB
01_random_17.txt AC 87 ms 22544 KiB
01_random_18.txt AC 88 ms 22712 KiB
01_random_19.txt AC 83 ms 22540 KiB
01_random_20.txt AC 87 ms 22556 KiB
01_random_21.txt AC 93 ms 22548 KiB
01_random_22.txt AC 78 ms 15368 KiB
01_random_23.txt AC 53 ms 15496 KiB
01_random_24.txt AC 46 ms 15156 KiB
01_random_25.txt AC 119 ms 24336 KiB
01_random_26.txt AC 120 ms 24332 KiB
01_random_27.txt AC 114 ms 24380 KiB
01_random_28.txt AC 115 ms 24328 KiB
01_random_29.txt AC 8 ms 9344 KiB
01_random_30.txt AC 8 ms 4676 KiB
01_random_31.txt AC 30 ms 8976 KiB
01_random_32.txt AC 55 ms 13472 KiB