답안 #39456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39456 2018-01-15T14:57:30 Z qoo2p5 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 5428 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;

#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define sz(x) ((int) (x).size())
#define mp make_pair
#define pb push_back

bool mini(auto &x, const auto &y) {
	if (y < x) {
		x = y;
		return 1;
	}
	return 0;
}

bool maxi(auto &x, const auto &y) {
	if (y < x) {
		x = y;
		return 1;
	}
	return 0;
}

void run();

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	run();
	return 0;
}

const int N = 30003;

int n, m;
int b[N], p[N];
int dist[N];
bool used[N];
vector<int> which[N];

void run() {
	cin >> n >> m;
	rep(i, 0, m) {
		cin >> b[i] >> p[i];
		which[b[i]].pb(p[i]);
	}
	
	fill(dist, dist + n, INF);
	dist[b[0]] = 0;
	priority_queue<pair<int, int>> q;
	q.push({0, b[0]});
	while (sz(q)) {
		int v = q.top().second;
		q.pop();
		if (used[v]) continue;
		used[v] = 1;
		for (int step : which[v]) {
			rep(i, 1, N) {
				int to = v + step * i;
				if (to >= n) break;
				if (mini(dist[to], dist[v] + i)) {
					q.push({-dist[to], to});
				}
			}
			rep(i, 1, N) {
				int to = v - step * i;
				if (to < 0) break;
				if (mini(dist[to], dist[v] + i)) {
					q.push({-dist[to], to});
				}
			}
		}
	}
	
	cout << (dist[b[1]] == INF ? -1 : dist[b[1]]) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3260 KB Output is correct
2 Correct 0 ms 3260 KB Output is correct
3 Correct 0 ms 3260 KB Output is correct
4 Correct 0 ms 3260 KB Output is correct
5 Correct 0 ms 3260 KB Output is correct
6 Correct 0 ms 3260 KB Output is correct
7 Correct 0 ms 3260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3260 KB Output is correct
2 Correct 0 ms 3260 KB Output is correct
3 Correct 0 ms 3260 KB Output is correct
4 Correct 0 ms 3260 KB Output is correct
5 Correct 0 ms 3260 KB Output is correct
6 Correct 0 ms 3260 KB Output is correct
7 Correct 0 ms 3260 KB Output is correct
8 Correct 0 ms 3260 KB Output is correct
9 Correct 0 ms 3260 KB Output is correct
10 Correct 0 ms 3260 KB Output is correct
11 Correct 0 ms 3260 KB Output is correct
12 Correct 0 ms 3260 KB Output is correct
13 Correct 0 ms 3260 KB Output is correct
14 Correct 0 ms 3260 KB Output is correct
15 Correct 0 ms 3260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3260 KB Output is correct
2 Correct 0 ms 3260 KB Output is correct
3 Correct 0 ms 3260 KB Output is correct
4 Correct 0 ms 3260 KB Output is correct
5 Correct 0 ms 3260 KB Output is correct
6 Correct 0 ms 3260 KB Output is correct
7 Correct 0 ms 3260 KB Output is correct
8 Correct 0 ms 3260 KB Output is correct
9 Correct 0 ms 3260 KB Output is correct
10 Correct 0 ms 3260 KB Output is correct
11 Correct 0 ms 3260 KB Output is correct
12 Correct 0 ms 3260 KB Output is correct
13 Correct 0 ms 3260 KB Output is correct
14 Correct 0 ms 3260 KB Output is correct
15 Correct 0 ms 3260 KB Output is correct
16 Correct 0 ms 3260 KB Output is correct
17 Correct 0 ms 3260 KB Output is correct
18 Correct 0 ms 3260 KB Output is correct
19 Correct 0 ms 3260 KB Output is correct
20 Correct 6 ms 3260 KB Output is correct
21 Correct 0 ms 3260 KB Output is correct
22 Correct 0 ms 3260 KB Output is correct
23 Correct 0 ms 3260 KB Output is correct
24 Correct 0 ms 3260 KB Output is correct
25 Correct 0 ms 3396 KB Output is correct
26 Correct 3 ms 3260 KB Output is correct
27 Correct 3 ms 3260 KB Output is correct
28 Correct 0 ms 3260 KB Output is correct
29 Correct 0 ms 3428 KB Output is correct
30 Correct 0 ms 3424 KB Output is correct
31 Correct 0 ms 3424 KB Output is correct
32 Correct 0 ms 3428 KB Output is correct
33 Correct 3 ms 3436 KB Output is correct
34 Correct 0 ms 3436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3260 KB Output is correct
2 Correct 0 ms 3260 KB Output is correct
3 Correct 0 ms 3260 KB Output is correct
4 Correct 0 ms 3260 KB Output is correct
5 Correct 0 ms 3260 KB Output is correct
6 Correct 0 ms 3260 KB Output is correct
7 Correct 0 ms 3260 KB Output is correct
8 Correct 0 ms 3260 KB Output is correct
9 Correct 0 ms 3260 KB Output is correct
10 Correct 0 ms 3260 KB Output is correct
11 Correct 0 ms 3260 KB Output is correct
12 Correct 0 ms 3260 KB Output is correct
13 Correct 0 ms 3260 KB Output is correct
14 Correct 0 ms 3260 KB Output is correct
15 Correct 0 ms 3260 KB Output is correct
16 Correct 0 ms 3260 KB Output is correct
17 Correct 0 ms 3260 KB Output is correct
18 Correct 0 ms 3260 KB Output is correct
19 Correct 0 ms 3260 KB Output is correct
20 Correct 6 ms 3260 KB Output is correct
21 Correct 0 ms 3260 KB Output is correct
22 Correct 0 ms 3260 KB Output is correct
23 Correct 0 ms 3260 KB Output is correct
24 Correct 0 ms 3260 KB Output is correct
25 Correct 0 ms 3396 KB Output is correct
26 Correct 3 ms 3260 KB Output is correct
27 Correct 3 ms 3260 KB Output is correct
28 Correct 0 ms 3260 KB Output is correct
29 Correct 0 ms 3428 KB Output is correct
30 Correct 0 ms 3424 KB Output is correct
31 Correct 0 ms 3424 KB Output is correct
32 Correct 0 ms 3428 KB Output is correct
33 Correct 0 ms 3436 KB Output is correct
34 Correct 3 ms 3436 KB Output is correct
35 Correct 3 ms 3524 KB Output is correct
36 Correct 3 ms 3260 KB Output is correct
37 Correct 3 ms 3544 KB Output is correct
38 Correct 13 ms 3524 KB Output is correct
39 Correct 6 ms 3524 KB Output is correct
40 Correct 13 ms 3524 KB Output is correct
41 Correct 6 ms 3524 KB Output is correct
42 Correct 76 ms 3424 KB Output is correct
43 Correct 69 ms 3424 KB Output is correct
44 Correct 69 ms 3420 KB Output is correct
45 Correct 9 ms 3532 KB Output is correct
46 Correct 6 ms 3532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3260 KB Output is correct
2 Correct 0 ms 3260 KB Output is correct
3 Correct 0 ms 3260 KB Output is correct
4 Correct 0 ms 3260 KB Output is correct
5 Correct 0 ms 3260 KB Output is correct
6 Correct 0 ms 3260 KB Output is correct
7 Correct 0 ms 3260 KB Output is correct
8 Correct 0 ms 3260 KB Output is correct
9 Correct 0 ms 3260 KB Output is correct
10 Correct 0 ms 3260 KB Output is correct
11 Correct 0 ms 3260 KB Output is correct
12 Correct 0 ms 3260 KB Output is correct
13 Correct 0 ms 3260 KB Output is correct
14 Correct 0 ms 3260 KB Output is correct
15 Correct 0 ms 3260 KB Output is correct
16 Correct 0 ms 3260 KB Output is correct
17 Correct 0 ms 3260 KB Output is correct
18 Correct 0 ms 3260 KB Output is correct
19 Correct 0 ms 3260 KB Output is correct
20 Correct 3 ms 3260 KB Output is correct
21 Correct 0 ms 3260 KB Output is correct
22 Correct 0 ms 3260 KB Output is correct
23 Correct 0 ms 3260 KB Output is correct
24 Correct 0 ms 3260 KB Output is correct
25 Correct 3 ms 3396 KB Output is correct
26 Correct 6 ms 3260 KB Output is correct
27 Correct 3 ms 3260 KB Output is correct
28 Correct 0 ms 3260 KB Output is correct
29 Correct 0 ms 3428 KB Output is correct
30 Correct 0 ms 3424 KB Output is correct
31 Correct 0 ms 3424 KB Output is correct
32 Correct 0 ms 3428 KB Output is correct
33 Correct 0 ms 3436 KB Output is correct
34 Correct 0 ms 3436 KB Output is correct
35 Correct 6 ms 3524 KB Output is correct
36 Correct 0 ms 3260 KB Output is correct
37 Correct 6 ms 3544 KB Output is correct
38 Correct 6 ms 3524 KB Output is correct
39 Correct 6 ms 3524 KB Output is correct
40 Correct 9 ms 3524 KB Output is correct
41 Correct 9 ms 3524 KB Output is correct
42 Correct 66 ms 3424 KB Output is correct
43 Correct 69 ms 3424 KB Output is correct
44 Correct 113 ms 3420 KB Output is correct
45 Correct 9 ms 3532 KB Output is correct
46 Correct 9 ms 3532 KB Output is correct
47 Correct 19 ms 4412 KB Output is correct
48 Correct 6 ms 3656 KB Output is correct
49 Correct 9 ms 3656 KB Output is correct
50 Correct 6 ms 3524 KB Output is correct
51 Correct 36 ms 5428 KB Output is correct
52 Correct 29 ms 4664 KB Output is correct
53 Correct 16 ms 4664 KB Output is correct
54 Correct 0 ms 3420 KB Output is correct
55 Correct 3 ms 3420 KB Output is correct
56 Execution timed out 1000 ms 4616 KB Execution timed out
57 Halted 0 ms 0 KB -