#include <cstdio>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Int long long
#define pb push_back
#define fore(i , m) for(int i = 0 ; i < m ; i++)
#define forn(i , x , y) for(int i = x ; i >= y;i--)
#define forr(i , x , y) for(int i = x ; i <= y; i++)
struct chash {
Int operator()(pair<Int ,Int> x) const { return x.first* 31ll + x.second; }
};
const Int INF = 1e18;
Int min_distance(vector<int> x, vector<int> h , vector<int> l , vector<int> r , vector<int> y , int s , int g)
{
int m = (int)l.size();
int n = (int)x.size();
map<int , int> degs[n];
vector<tuple<int ,int,int>> lines;
fore(i , m)
{
lines.pb({y[i] , l[i] , r[i]});
}
sort(lines.begin() , lines.end());
map<pair<int ,int> , vector<pair<pair<int , int> , int>> > adj;
fore(i , n)
{
degs[i][0] = i;
}
for(auto [Y , L , R] : lines)
{
forr(i , L , R)
{
if(h[i]>= Y)
{
degs[i][Y] = max(degs[i][Y] , R);
}
}
}
map<pair<int , int> , Int > dist;
fore(i , n)
{
for(auto it = degs[i].begin() ; it != (degs[i].end()) ; it++)
{
auto [Y , R] = *it;
dist[{i , Y}] = INF;
if(Y != 0)
{
forr(j , i + 1 , R)
{
if(h[j] >= Y)
{
adj[{i , Y}].pb({{j , Y} , x[j] - x[i]});
adj[{j , Y}].pb({{i , Y} , x[j] - x[i]});
break;
}
}
}
if(it == prev(degs[i].end()))
break;
auto [nY , nR] = *next(it);
adj[{i , Y}].pb({{i , nY} , nY - Y});
adj[{i , nY}].pb({{i , Y} , nY - Y});
}
}
priority_queue<pair<Int , pair<int , int>>> pq;
pq.push({0 , {s , 0}});
map<pair<int , int> , int > vis;
dist[{s , 0}] = 0;
while(!pq.empty())
{
auto tp = pq.top();
pq.pop();
if(vis[tp.second] == 1)
continue;
vis[tp.second] = 1;
auto [i , Y] = tp.second;
for(auto p : adj[{i , Y}])
{
Int w = p.second;
auto [j , nY] = p.first;
if(dist[{j , nY}] > dist[{i , Y}] + w)
{
pq.push({-dist[{i , Y}] - w , {j , nY}});
dist[{j , nY}] = w + dist[{i , Y}];
}
}
}
if(dist[{g , 0}] >= INF)
{
return -1ll;
}
return dist[{g , 0}];
}
//signed main() {
// int n, m;
// assert(2 == scanf("%d%d", &n, &m));
// vector<int> x(n), h(n);
// for (int i = 0; i < n; i++)
// assert(2 == scanf("%d%d", &x[i], &h[i]));
// vector<int> l(m), r(m), y(m);
// for (int i = 0; i < m; i++)
// assert(3 == scanf("%d%d%d", &l[i], &r[i], &y[i]));
// int s, g;
// assert(2 == scanf("%d%d", &s, &g));
// fclose(stdin);
//
// long long result = min_distance(x, h, l, r, y, s, g);
//
// printf("%lld\n", result);
// fclose(stdout);
// return 0;
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2389 ms |
226476 KB |
Output is correct |
4 |
Correct |
1721 ms |
256132 KB |
Output is correct |
5 |
Correct |
733 ms |
180576 KB |
Output is correct |
6 |
Correct |
1170 ms |
160616 KB |
Output is correct |
7 |
Correct |
709 ms |
180680 KB |
Output is correct |
8 |
Correct |
3173 ms |
288972 KB |
Output is correct |
9 |
Correct |
815 ms |
183240 KB |
Output is correct |
10 |
Correct |
2645 ms |
350404 KB |
Output is correct |
11 |
Correct |
906 ms |
126408 KB |
Output is correct |
12 |
Correct |
454 ms |
97852 KB |
Output is correct |
13 |
Correct |
2229 ms |
308332 KB |
Output is correct |
14 |
Correct |
2980 ms |
75972 KB |
Output is correct |
15 |
Correct |
1837 ms |
97796 KB |
Output is correct |
16 |
Correct |
540 ms |
98760 KB |
Output is correct |
17 |
Correct |
504 ms |
95436 KB |
Output is correct |
18 |
Execution timed out |
4014 ms |
20428 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
24236 KB |
Output is correct |
2 |
Execution timed out |
4080 ms |
774344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
24236 KB |
Output is correct |
2 |
Execution timed out |
4080 ms |
774344 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
2389 ms |
226476 KB |
Output is correct |
21 |
Correct |
1721 ms |
256132 KB |
Output is correct |
22 |
Correct |
733 ms |
180576 KB |
Output is correct |
23 |
Correct |
1170 ms |
160616 KB |
Output is correct |
24 |
Correct |
709 ms |
180680 KB |
Output is correct |
25 |
Correct |
3173 ms |
288972 KB |
Output is correct |
26 |
Correct |
815 ms |
183240 KB |
Output is correct |
27 |
Correct |
2645 ms |
350404 KB |
Output is correct |
28 |
Correct |
906 ms |
126408 KB |
Output is correct |
29 |
Correct |
454 ms |
97852 KB |
Output is correct |
30 |
Correct |
2229 ms |
308332 KB |
Output is correct |
31 |
Correct |
2980 ms |
75972 KB |
Output is correct |
32 |
Correct |
1837 ms |
97796 KB |
Output is correct |
33 |
Correct |
540 ms |
98760 KB |
Output is correct |
34 |
Correct |
504 ms |
95436 KB |
Output is correct |
35 |
Execution timed out |
4014 ms |
20428 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |