답안 #622773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
622773 2022-08-04T14:20:07 Z cheissmart Sky Walking (IOI19_walk) C++14
43 / 100
4000 ms 24072 KB
#include "walk.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define V vector
#define MP make_pair
#define EB emplace_back
#define PB push_back
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 1e5 + 7;
const ll oo = 1e18;

vi asr[N], asl[N];
map<int, ll> dist[N];

ll brute(vi& x, vi& h, vi& l, vi& r, vi& y, int s, int g) {
	int n = SZ(x);
	int m = SZ(l);
	vi ys = y;
	ys.PB(0);
	auto get_edges = [&] (int i, int yy) {
		V<pair<pi, int>> res;
		for(int yyy:ys) if(yyy <= h[i]) {
			res.EB(pi(i, yyy), abs(yy - yyy));
		}
		for(int j = 0; j < m; j++) {
			if(y[j] == yy && l[j] <= i && i <= r[j]) {
				for(int k = l[j]; k <= r[j]; k++) if(yy <= h[k]) {
					res.EB(pi(k, yy), abs(x[i] - x[k]));
				}
			}
		}
		return res;
	};
	priority_queue<pair<ll, pi>, V<pair<ll, pi>>, greater<pair<ll, pi>>> pq;
	pq.push(MP(0, pi(s, 0)));
	dist[s][0] = 0;
	
	while(pq.size()) {
		auto[dd, state] = pq.top(); pq.pop();
		auto[i, yy] = state;
		if(dd > dist[i][yy]) continue;
		V<pair<pi, int>> res = get_edges(i, yy);
		for(auto[nstate, w]:res) {
			auto[ni, nyy] = nstate;
			if(dist[ni].count(nyy) == 0 || dd + w < dist[ni][nyy]) {
				dist[ni][nyy] = dd + w;
				pq.push(MP(dd + w, nstate));
			}
		}
	}

	if(dist[g].count(0))
		return dist[g][0];
	return -1;
}

ll min_distance(vi x, vi h, vi l, vi r, vi y, int s, int g) {
	int n = SZ(x);
	int m = SZ(l);
	if(s != 0 || g != n - 1) {
		return brute(x, h, l, r, y, s, g);
	}

	for(int i = 0; i < m; i++) {
		asl[l[i]].PB(y[i]);
		asr[r[i]].PB(y[i]);
	}
	map<int, ll> mp;
	mp[0] = 0;
	asr[0].PB(0);

	for(int i = 0; i < n; i++) {
		set<int> no;
		for(int yy:asl[i]) {
			no.insert(yy);
			auto it = mp.lower_bound(yy);
			ll d = oo;
			if(it != mp.end()) 
				d = min(d, it -> S + abs(yy - it -> F));
			if(it != mp.begin()) {
				it--;
				d = min(d, it -> S + abs(yy - it -> F));
			}
			mp[yy] = d;
		}
		if(i < n - 1) for(int yy:asr[i]) {
			if(no.count(yy)) continue;
			mp.erase(yy);
		}
		if(mp.empty()) return -1;
	}

	ll ans = oo;
	for(auto[yy, d]:mp)
		ans = min(ans, d + yy);
	return ans + x[n - 1] - x[0];
}

Compilation message

walk.cpp: In function 'll brute(vi&, vi&, vi&, vi&, vi&, int, int)':
walk.cpp:48:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |   auto[dd, state] = pq.top(); pq.pop();
      |       ^
walk.cpp:49:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |   auto[i, yy] = state;
      |       ^
walk.cpp:52:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |   for(auto[nstate, w]:res) {
      |           ^
walk.cpp:53:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   53 |    auto[ni, nyy] = nstate;
      |        ^
walk.cpp:25:6: warning: unused variable 'n' [-Wunused-variable]
   25 |  int n = SZ(x);
      |      ^
walk.cpp: In function 'll min_distance(vi, vi, vi, vi, vi, int, int)':
walk.cpp:103:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  103 |  for(auto[yy, d]:mp)
      |          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9692 KB Output is correct
5 Correct 11 ms 9808 KB Output is correct
6 Correct 8 ms 9684 KB Output is correct
7 Correct 8 ms 9792 KB Output is correct
8 Correct 8 ms 9696 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 11 ms 9780 KB Output is correct
11 Correct 8 ms 9684 KB Output is correct
12 Correct 6 ms 9704 KB Output is correct
13 Correct 7 ms 9696 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9812 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9692 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Execution timed out 4019 ms 24072 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 12136 KB Output is correct
2 Correct 92 ms 13740 KB Output is correct
3 Correct 95 ms 14272 KB Output is correct
4 Correct 122 ms 18048 KB Output is correct
5 Correct 162 ms 22540 KB Output is correct
6 Correct 143 ms 20344 KB Output is correct
7 Correct 63 ms 15460 KB Output is correct
8 Correct 87 ms 20096 KB Output is correct
9 Correct 142 ms 21896 KB Output is correct
10 Correct 108 ms 21736 KB Output is correct
11 Correct 14 ms 10740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 12136 KB Output is correct
2 Correct 92 ms 13740 KB Output is correct
3 Correct 95 ms 14272 KB Output is correct
4 Correct 122 ms 18048 KB Output is correct
5 Correct 162 ms 22540 KB Output is correct
6 Correct 143 ms 20344 KB Output is correct
7 Correct 63 ms 15460 KB Output is correct
8 Correct 87 ms 20096 KB Output is correct
9 Correct 142 ms 21896 KB Output is correct
10 Correct 108 ms 21736 KB Output is correct
11 Correct 14 ms 10740 KB Output is correct
12 Correct 111 ms 14276 KB Output is correct
13 Correct 97 ms 17788 KB Output is correct
14 Correct 167 ms 22536 KB Output is correct
15 Correct 112 ms 18060 KB Output is correct
16 Correct 102 ms 18040 KB Output is correct
17 Correct 98 ms 18040 KB Output is correct
18 Correct 103 ms 18068 KB Output is correct
19 Correct 108 ms 18184 KB Output is correct
20 Correct 71 ms 15584 KB Output is correct
21 Correct 27 ms 11612 KB Output is correct
22 Correct 111 ms 16080 KB Output is correct
23 Correct 89 ms 16380 KB Output is correct
24 Correct 91 ms 17828 KB Output is correct
25 Correct 82 ms 16332 KB Output is correct
26 Correct 92 ms 20432 KB Output is correct
27 Correct 145 ms 22012 KB Output is correct
28 Correct 84 ms 17664 KB Output is correct
29 Correct 147 ms 20428 KB Output is correct
30 Correct 67 ms 15544 KB Output is correct
31 Correct 135 ms 21784 KB Output is correct
32 Correct 88 ms 19884 KB Output is correct
33 Correct 91 ms 20840 KB Output is correct
34 Correct 95 ms 20208 KB Output is correct
35 Correct 93 ms 18904 KB Output is correct
36 Correct 81 ms 18508 KB Output is correct
37 Correct 70 ms 18112 KB Output is correct
38 Correct 86 ms 20128 KB Output is correct
39 Correct 97 ms 21832 KB Output is correct
40 Correct 81 ms 19908 KB Output is correct
41 Correct 76 ms 18548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9692 KB Output is correct
5 Correct 11 ms 9808 KB Output is correct
6 Correct 8 ms 9684 KB Output is correct
7 Correct 8 ms 9792 KB Output is correct
8 Correct 8 ms 9696 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 11 ms 9780 KB Output is correct
11 Correct 8 ms 9684 KB Output is correct
12 Correct 6 ms 9704 KB Output is correct
13 Correct 7 ms 9696 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 6 ms 9812 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 5 ms 9692 KB Output is correct
19 Correct 7 ms 9684 KB Output is correct
20 Execution timed out 4019 ms 24072 KB Time limit exceeded
21 Halted 0 ms 0 KB -