#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#define eb emplace_back
#define ALL(i) i.begin(),i.end()
#define X first
#define Y second
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
os<<"{";
for(It it=bg;it!=ed;it++) {
os<<(it==bg?"":",")<<*it;
}
os<<"}";
return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif
const int MAXN = 100005;
map<int,int> pil[MAXN];
vector<int> add[MAXN], rmv[MAXN];
int nnd;
int n, m;
vector<pii> edge[MAXN*12];
ll dis[MAXN*12];
bool vis[MAXN*12];
priority_queue<pli, vector<pli>, greater<pli> > pq;
void add_edge (int u, int v, int w) {
edge[u].eb(v, w);
edge[v].eb(u, w);
debug(u, v, w);
}
ll dijk (int s, int t) {
memset(dis, 0x3f, sizeof(dis));
dis[s] = 0;
pq.emplace(0, s);
while (pq.size()) {
int nd = pq.top().Y;
pq.pop();
// debug(nd);
if (vis[nd]) {
continue;
}
vis[nd] = true;
for (auto e : edge[nd]) {
// debug(e.X, e.Y, dis[e.X]);
if (dis[e.X] > dis[nd] + e.Y) {
dis[e.X] = dis[nd] + e.Y;
pq.emplace(dis[e.X], e.X);
// debug(dis[e.X], e.X);
}
}
}
return dis[t] == 0x3f3f3f3f3f3f3f3f ? -1 : dis[t];
}
set<pii> sid;
int lid[MAXN];
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
n = SZ(x);
m = SZ(y);
REP (i, m) {
add[l[i]].eb(i);
rmv[r[i]].eb(i);
}
memset(lid, -1, sizeof(lid));
nnd = n;
REP (i, n) {
for (auto v : add[i]) {
sid.insert({y[v], v});
}
for (auto v : sid) {
if (v.X <= h[i]) {
if (pil[i].count(v.X) == 0) {
pil[i][v.X] = nnd++;
}
if (lid[v.Y] != -1) {
add_edge(nnd-1, pil[lid[v.Y]][v.X], x[i] - x[lid[v.Y]]);
}
lid[v.Y] = i;
} else {
break;
}
}
for (auto v : rmv[i]) {
sid.erase({y[v], v});
}
}
REP (i, n) {
int lv = i;
int lh = 0;
for (auto v : pil[i]) {
debug(v.X, v.Y);
add_edge(lv, v.Y, v.X - lh);
lh = v.X;
lv = v.Y;
}
}
return dijk(s, g);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
47608 KB |
Output is correct |
2 |
Correct |
32 ms |
47608 KB |
Output is correct |
3 |
Correct |
33 ms |
47736 KB |
Output is correct |
4 |
Correct |
31 ms |
47736 KB |
Output is correct |
5 |
Correct |
32 ms |
47736 KB |
Output is correct |
6 |
Correct |
32 ms |
47736 KB |
Output is correct |
7 |
Correct |
31 ms |
47736 KB |
Output is correct |
8 |
Correct |
32 ms |
47736 KB |
Output is correct |
9 |
Correct |
33 ms |
47736 KB |
Output is correct |
10 |
Correct |
33 ms |
47736 KB |
Output is correct |
11 |
Correct |
33 ms |
47736 KB |
Output is correct |
12 |
Correct |
32 ms |
47736 KB |
Output is correct |
13 |
Correct |
32 ms |
47736 KB |
Output is correct |
14 |
Correct |
31 ms |
47736 KB |
Output is correct |
15 |
Correct |
32 ms |
47736 KB |
Output is correct |
16 |
Correct |
33 ms |
47736 KB |
Output is correct |
17 |
Correct |
33 ms |
47736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
47736 KB |
Output is correct |
2 |
Correct |
31 ms |
47736 KB |
Output is correct |
3 |
Correct |
600 ms |
135672 KB |
Output is correct |
4 |
Correct |
588 ms |
140920 KB |
Output is correct |
5 |
Correct |
400 ms |
126328 KB |
Output is correct |
6 |
Correct |
356 ms |
116216 KB |
Output is correct |
7 |
Correct |
387 ms |
126328 KB |
Output is correct |
8 |
Correct |
771 ms |
160504 KB |
Output is correct |
9 |
Correct |
442 ms |
125408 KB |
Output is correct |
10 |
Correct |
793 ms |
176132 KB |
Output is correct |
11 |
Correct |
361 ms |
95208 KB |
Output is correct |
12 |
Correct |
227 ms |
82532 KB |
Output is correct |
13 |
Correct |
676 ms |
166392 KB |
Output is correct |
14 |
Correct |
232 ms |
78328 KB |
Output is correct |
15 |
Correct |
229 ms |
80120 KB |
Output is correct |
16 |
Correct |
232 ms |
82296 KB |
Output is correct |
17 |
Correct |
224 ms |
80760 KB |
Output is correct |
18 |
Correct |
307 ms |
77796 KB |
Output is correct |
19 |
Correct |
39 ms |
49148 KB |
Output is correct |
20 |
Correct |
113 ms |
62924 KB |
Output is correct |
21 |
Correct |
201 ms |
80504 KB |
Output is correct |
22 |
Correct |
212 ms |
81656 KB |
Output is correct |
23 |
Correct |
344 ms |
88428 KB |
Output is correct |
24 |
Correct |
225 ms |
81916 KB |
Output is correct |
25 |
Correct |
224 ms |
80356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
57336 KB |
Output is correct |
2 |
Runtime error |
700 ms |
274924 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
57336 KB |
Output is correct |
2 |
Runtime error |
700 ms |
274924 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
47608 KB |
Output is correct |
2 |
Correct |
32 ms |
47608 KB |
Output is correct |
3 |
Correct |
33 ms |
47736 KB |
Output is correct |
4 |
Correct |
31 ms |
47736 KB |
Output is correct |
5 |
Correct |
32 ms |
47736 KB |
Output is correct |
6 |
Correct |
32 ms |
47736 KB |
Output is correct |
7 |
Correct |
31 ms |
47736 KB |
Output is correct |
8 |
Correct |
32 ms |
47736 KB |
Output is correct |
9 |
Correct |
33 ms |
47736 KB |
Output is correct |
10 |
Correct |
33 ms |
47736 KB |
Output is correct |
11 |
Correct |
33 ms |
47736 KB |
Output is correct |
12 |
Correct |
32 ms |
47736 KB |
Output is correct |
13 |
Correct |
32 ms |
47736 KB |
Output is correct |
14 |
Correct |
31 ms |
47736 KB |
Output is correct |
15 |
Correct |
32 ms |
47736 KB |
Output is correct |
16 |
Correct |
33 ms |
47736 KB |
Output is correct |
17 |
Correct |
33 ms |
47736 KB |
Output is correct |
18 |
Correct |
35 ms |
47736 KB |
Output is correct |
19 |
Correct |
31 ms |
47736 KB |
Output is correct |
20 |
Correct |
600 ms |
135672 KB |
Output is correct |
21 |
Correct |
588 ms |
140920 KB |
Output is correct |
22 |
Correct |
400 ms |
126328 KB |
Output is correct |
23 |
Correct |
356 ms |
116216 KB |
Output is correct |
24 |
Correct |
387 ms |
126328 KB |
Output is correct |
25 |
Correct |
771 ms |
160504 KB |
Output is correct |
26 |
Correct |
442 ms |
125408 KB |
Output is correct |
27 |
Correct |
793 ms |
176132 KB |
Output is correct |
28 |
Correct |
361 ms |
95208 KB |
Output is correct |
29 |
Correct |
227 ms |
82532 KB |
Output is correct |
30 |
Correct |
676 ms |
166392 KB |
Output is correct |
31 |
Correct |
232 ms |
78328 KB |
Output is correct |
32 |
Correct |
229 ms |
80120 KB |
Output is correct |
33 |
Correct |
232 ms |
82296 KB |
Output is correct |
34 |
Correct |
224 ms |
80760 KB |
Output is correct |
35 |
Correct |
307 ms |
77796 KB |
Output is correct |
36 |
Correct |
39 ms |
49148 KB |
Output is correct |
37 |
Correct |
113 ms |
62924 KB |
Output is correct |
38 |
Correct |
201 ms |
80504 KB |
Output is correct |
39 |
Correct |
212 ms |
81656 KB |
Output is correct |
40 |
Correct |
344 ms |
88428 KB |
Output is correct |
41 |
Correct |
225 ms |
81916 KB |
Output is correct |
42 |
Correct |
224 ms |
80356 KB |
Output is correct |
43 |
Correct |
94 ms |
57336 KB |
Output is correct |
44 |
Runtime error |
700 ms |
274924 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
45 |
Halted |
0 ms |
0 KB |
- |