Submission #590869

# Submission time Handle Problem Language Result Execution time Memory
590869 2022-07-06T12:31:43 Z 8e7 Sky Walking (IOI19_walk) C++17
33 / 100
659 ms 100900 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 1000005
#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> lft[maxn], rht[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++) {
		lft[L[i]].push_back(i);	
		rht[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++) {
			vector<int> ev = lft[i];
			ev.insert(ev.end(), rht[i].begin(), rht[i].end());
			for (int id:ev) {
				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)));
					debug("end");
					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);
      |   ^~~~~
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
walk.cpp:52:6: note: in expansion of macro 'debug'
   52 |      debug("end");
      |      ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 36276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 36308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 60096 KB Output is correct
2 Correct 377 ms 88048 KB Output is correct
3 Correct 419 ms 90748 KB Output is correct
4 Correct 463 ms 96496 KB Output is correct
5 Correct 645 ms 99912 KB Output is correct
6 Correct 619 ms 98980 KB Output is correct
7 Correct 193 ms 69320 KB Output is correct
8 Correct 195 ms 76384 KB Output is correct
9 Correct 594 ms 100900 KB Output is correct
10 Correct 355 ms 93776 KB Output is correct
11 Correct 27 ms 37844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 60096 KB Output is correct
2 Correct 377 ms 88048 KB Output is correct
3 Correct 419 ms 90748 KB Output is correct
4 Correct 463 ms 96496 KB Output is correct
5 Correct 645 ms 99912 KB Output is correct
6 Correct 619 ms 98980 KB Output is correct
7 Correct 193 ms 69320 KB Output is correct
8 Correct 195 ms 76384 KB Output is correct
9 Correct 594 ms 100900 KB Output is correct
10 Correct 355 ms 93776 KB Output is correct
11 Correct 27 ms 37844 KB Output is correct
12 Correct 385 ms 90744 KB Output is correct
13 Correct 286 ms 96196 KB Output is correct
14 Correct 654 ms 99756 KB Output is correct
15 Correct 372 ms 81256 KB Output is correct
16 Correct 373 ms 96268 KB Output is correct
17 Correct 402 ms 96236 KB Output is correct
18 Correct 353 ms 81240 KB Output is correct
19 Correct 381 ms 96332 KB Output is correct
20 Correct 250 ms 69068 KB Output is correct
21 Correct 48 ms 40456 KB Output is correct
22 Correct 322 ms 87228 KB Output is correct
23 Correct 338 ms 88652 KB Output is correct
24 Correct 333 ms 84848 KB Output is correct
25 Correct 324 ms 84552 KB Output is correct
26 Correct 288 ms 81476 KB Output is correct
27 Correct 659 ms 99908 KB Output is correct
28 Correct 298 ms 95812 KB Output is correct
29 Correct 631 ms 98832 KB Output is correct
30 Correct 201 ms 69252 KB Output is correct
31 Correct 596 ms 100876 KB Output is correct
32 Correct 243 ms 87492 KB Output is correct
33 Correct 316 ms 89888 KB Output is correct
34 Correct 306 ms 94980 KB Output is correct
35 Correct 273 ms 89340 KB Output is correct
36 Correct 221 ms 81948 KB Output is correct
37 Correct 182 ms 81408 KB Output is correct
38 Correct 223 ms 88640 KB Output is correct
39 Correct 363 ms 97484 KB Output is correct
40 Correct 240 ms 85824 KB Output is correct
41 Correct 179 ms 81068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 36276 KB Output isn't correct
2 Halted 0 ms 0 KB -