이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct treatment {
int t, l, r, c;
pair<int, int> pocz, kon;
void read()
{
cin >> t >> l >> r >> c;
r++;
pocz.first = l + t;
pocz.second = t - l;
kon.first = r + t;
kon.second = t - r;
}
};
int main()
{
cin.tie(nullptr)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<treatment> they(m + 1);
for(int i = 1; i <= m; i++) {
they[i].read();
}
#define T pair<long long, int>
priority_queue<T, vector<T>, greater<T>> q;
const long long ool = 1e18 + 5;
vector<long long> d(m + 1);
for(int i = 1; i <= m; i++) {
if(they[i].l == 1) {
d[i] = they[i].c;
q.push({d[i], i});
}
else {
d[i] = ool;
}
}
while(!q.empty()) {
pair<long long, int> t = q.top();
q.pop();
assert(t.first == d[t.second]);
for(int i = 1; i <= m; i++) {
if(d[i] > t.first + they[i].c && they[i].pocz.first <= they[t.second].kon.first && they[i].pocz.second >= they[t.second].kon.second) {
q.emplace(d[i] = t.first + they[i].c, i);
}
}
}
long long ans = ool;
for(int i = 1; i <= m; i++) {
if(they[i].r == n + 1) {
ans = min(ans, d[i]);
}
}
cout << (ans == ool ? -1 : ans) << '\n';
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |