Submission #1169872

#TimeUsernameProblemLanguageResultExecution timeMemory
1169872Sharky치료 계획 (JOI20_treatment)C++20
5 / 100
1 ms584 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif #define int long long #define fi first #define se second #define L(i, j, k) for (int i = (j); i <= (k); i++) #define R(i, j, k) for (int i = (j); i >= (k); i--) #define all(x) x.begin(), x.end() const int N = 3005; const int inf = 1e18; struct Treatment { int t, l, r, c; } arr[N]; int di[N]; vector<pair<int, int>> adj[2 * N]; void ae(int u, int v, int w) { // cout << "addedge: " << u << " " << v << " " << w << '\n'; adj[u].push_back({v, w}); } void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) cin >> arr[i].t >> arr[i].l >> arr[i].r >> arr[i].c; for (int i = 1; i <= m; i++) { for (int j = 1; j <= m; j++) { if (i == j) continue; int td = abs(arr[i].t - arr[j].t); if (arr[j].l <= arr[i].r + 1 - td) ae(i, j, arr[j].c); } if (arr[i].l == 1) ae(0, i, arr[i].c); } di[0] = 0; for (int i = 1; i <= m; i++) di[i] = inf; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q; q.push({0, 0}); while (!q.empty()) { auto [d, u] = q.top(); q.pop(); if (d != di[u]) continue; for (auto& [v, w] : adj[u]) { if (di[v] > di[u] + w) { di[v] = di[u] + w; q.push({di[v], v}); } } } int ans = inf; for (int i = 1; i <= m; i++) if (arr[i].r == n) ans = min(ans, di[i]); if (ans == inf) cout << "-1\n"; else cout << ans << '\n'; // sort projects, then point to interval edges } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int test = 1; // cin >> test; while (test--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...