#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>
typedef long long llong;
const int MAXN = 100000 + 10;
const llong INF = 1e18;
int n, m;
struct Interval
{
int t, l, r, c;
friend bool operator < (const Interval &a, const Interval &b)
{
return a.r < b.r;
}
};
bool vis[MAXN];
Interval a[MAXN];
llong dist[MAXN];
std::vector <std::pair <int,int>> g[MAXN];
std::priority_queue <std::pair <llong,int>> pq;
void solve()
{
// std::sort(a + 1, a + 1 + n);
for (int i = 1 ; i <= n ; ++i)
{
for (int j = 1 ; j <= n ; ++j)
{
if (i != j && a[i].r - a[j].l + 1 >= abs(a[i].t - a[j].t))
{
g[i].push_back({j, a[j].c});
}
}
}
llong ans = INF;
for (int i = 1 ; i <= n ; ++i)
{
dist[i] = INF;
if (a[i].l == 1)
{
dist[i] = a[i].c;
pq.push({-dist[i], i});
}
}
while (pq.size())
{
auto [currDist, node] = pq.top();
pq.pop();
if (a[node].r == m)
{
ans = dist[node];
break;
}
if (vis[node])
{
continue;
}
vis[node] = true;
for (const auto &[u, w] : g[node])
{
if (dist[u] > dist[node] + w)
{
dist[u] = dist[node] + w;
pq.push({-dist[u], u});
}
}
}
if (ans == INF) std::cout << -1 << '\n';
else std::cout << ans << '\n';
}
void input()
{
std::cin >> m >> n;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
919 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4704 KB |
Output is correct |
4 |
Correct |
2 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4744 KB |
Output is correct |
11 |
Correct |
1 ms |
4704 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4748 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4696 KB |
Output is correct |
16 |
Correct |
2 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4704 KB |
Output is correct |
4 |
Correct |
2 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4744 KB |
Output is correct |
11 |
Correct |
1 ms |
4704 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4748 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4696 KB |
Output is correct |
16 |
Correct |
2 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
221 ms |
133516 KB |
Output is correct |
21 |
Correct |
216 ms |
133204 KB |
Output is correct |
22 |
Correct |
39 ms |
7504 KB |
Output is correct |
23 |
Correct |
39 ms |
7508 KB |
Output is correct |
24 |
Correct |
154 ms |
97392 KB |
Output is correct |
25 |
Correct |
112 ms |
68176 KB |
Output is correct |
26 |
Correct |
107 ms |
65104 KB |
Output is correct |
27 |
Correct |
126 ms |
79040 KB |
Output is correct |
28 |
Correct |
149 ms |
96824 KB |
Output is correct |
29 |
Correct |
107 ms |
67236 KB |
Output is correct |
30 |
Correct |
111 ms |
75344 KB |
Output is correct |
31 |
Correct |
118 ms |
80724 KB |
Output is correct |
32 |
Correct |
199 ms |
124752 KB |
Output is correct |
33 |
Correct |
274 ms |
193360 KB |
Output is correct |
34 |
Correct |
198 ms |
123988 KB |
Output is correct |
35 |
Correct |
193 ms |
124756 KB |
Output is correct |
36 |
Correct |
256 ms |
193052 KB |
Output is correct |
37 |
Correct |
200 ms |
123728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
919 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |