# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
590857 |
2022-07-06T12:23:52 Z |
8e7 |
Sky Walking (IOI19_walk) |
C++17 |
|
75 ms |
41092 KB |
//Challenge: Accepted
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r)cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define maxv 500005
#define pii pair<ll, ll>
#define ff first
#define ss second
const ll inf = 1LL<<60;
vector<pii> adj[maxv];
ll dis[maxv];
int prv[maxn], px[maxn];
vector<int> ev[maxn];
bool on[maxn];
long long min_distance(vector<int> X, vector<int> H, vector<int> L, vector<int> R, vector<int> Y, int st, int ed) {
int n = X.size(), m = L.size();
set<pii> se;
for (int i = 0;i < m;i++) {
ev[L[i]].push_back(i);
ev[R[i]].push_back(i);
}
auto addedge = [&] (int u, int v, int w){
adj[u].push_back({v, w});
adj[v].push_back({u, w});
debug(u, v, w);
};
int term = maxv - 1;
{
int cur = 1;
for (int i = 0;i < n;i++) {
for (int id:ev[i]) {
int y = Y[id], node = cur++;
if (on[id]) {
if (i == n - 1) addedge(node, term, y);
se.erase(se.find(make_pair(y, id)));
addedge(node, prv[id], X[i] - px[id]);
}
auto it = se.lower_bound(make_pair(y, id));
if (it != se.end()) {
addedge(cur, prv[it->ss], X[i] - px[it->ss]);
prv[it->ss] = cur;
px[it->ss] = X[i];
addedge(node, cur++, abs(y - it->ff));
}
if (it != se.begin()) {
it = prev(it);
addedge(cur, prv[it->ss], X[i] - px[it->ss]);
prv[it->ss] = cur;
px[it->ss] = X[i];
addedge(node, cur++, abs(y - it->ff));
}
if (!on[id]) {
if (i == 0) addedge(node, 0, y);
se.insert(make_pair(y, id));
prv[id] = node;
px[id] = X[i];
on[id] = 1;
}
}
}
}
for (int i = 0;i < maxv;i++) dis[i] = inf;
dis[0] = 0;
priority_queue<pii, vector<pii>, greater<pii> > pq;
pq.push({0, 0});
while (pq.size()) {
auto [d, cur] = pq.top();
pq.pop();
if (d != dis[cur]) continue;
for (auto [v, w]:adj[cur]) {
if (d + w < dis[v]) {
dis[v] = d + w;
pq.push({dis[v], v});
}
}
}
if (dis[term] == inf) return -1;
return dis[term];
}
Compilation message
walk.cpp: In lambda function:
walk.cpp:13:20: warning: statement has no effect [-Wunused-value]
13 | #define debug(...) 0
| ^
walk.cpp:38:3: note: in expansion of macro 'debug'
38 | debug(u, v, w);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
18260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
18244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
41092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
41092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
18260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |