#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
struct gujo
{
ll T, L, R, C;
};
ll n, m;
gujo a[100010];
vector<pll> vec[100010];
ll dist[100010];
ll ans;
void dijkstra(void)
{
priority_queue<pll> pq;
for(ll i = 1 ; i <= m ; i++)
dist[i] = INF;
for(ll i = 1 ; i <= m ; i++)
{
if(a[i].L == 1)
{
dist[i] = 0;
pq.push({0, i});
}
}
while(!pq.empty())
{
pll qq = pq.top();
pq.pop();
for(auto &i : vec[qq.se])
{
if(dist[i.fi] > dist[qq.se] + i.se)
{
dist[i.fi] = dist[qq.se] + i.se;
pq.push({-dist[i.fi], i.fi});
}
}
}
ans = INF;
for(ll i = 1 ; i <= m ; i++)
{
if(a[i].R == n)
ans = min(ans, dist[i] + a[i].C);
}
if(ans == INF)
cout << -1;
else
cout << ans;
}
int main(void)
{
fastio
cin >> n >> m;
for(ll i = 1 ; i <= m ; i++)
cin >> a[i].T >> a[i].L >> a[i].R >> a[i].C;
for(ll i = 1 ; i <= m ; i++)
{
for(ll j = 1 ; j <= m ; j++)
{
if(i == j)
continue;
if(a[i].R + a[i].T + 1 >= a[j].L + a[j].T && a[i].R - a[i].T + 1 >= a[j].L - a[j].T)
vec[i].push_back({j, a[i].C});
}
}
dijkstra();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
538 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4568 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4568 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4568 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4568 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4568 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4568 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
307 ms |
250192 KB |
Output is correct |
21 |
Correct |
317 ms |
249996 KB |
Output is correct |
22 |
Correct |
89 ms |
9808 KB |
Output is correct |
23 |
Correct |
87 ms |
9776 KB |
Output is correct |
24 |
Correct |
240 ms |
178964 KB |
Output is correct |
25 |
Correct |
138 ms |
121816 KB |
Output is correct |
26 |
Correct |
125 ms |
116152 KB |
Output is correct |
27 |
Correct |
160 ms |
141736 KB |
Output is correct |
28 |
Correct |
223 ms |
177300 KB |
Output is correct |
29 |
Correct |
130 ms |
120088 KB |
Output is correct |
30 |
Correct |
146 ms |
135760 KB |
Output is correct |
31 |
Correct |
143 ms |
144720 KB |
Output is correct |
32 |
Correct |
356 ms |
231232 KB |
Output is correct |
33 |
Correct |
596 ms |
359992 KB |
Output is correct |
34 |
Correct |
258 ms |
230564 KB |
Output is correct |
35 |
Correct |
292 ms |
231164 KB |
Output is correct |
36 |
Correct |
378 ms |
358976 KB |
Output is correct |
37 |
Correct |
254 ms |
230320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
538 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |