답안 #315867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315867 2020-10-24T07:48:43 Z parsabahrami Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
948 ms 7160 KB
//! Starman - Dawid Bowie
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;
 
#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
        if (b & 1)
            ans = ans * a % md;
    return ans % md;
}
const ll MAXN = 5e4 + 10;
const ll INF  = 1e18;
const ll MOD  = 1e9 + 7;
priority_queue<pll> pq; vector<ll> vec[MAXN];
ll mark[MAXN], dist[MAXN], B[MAXN], P[MAXN], st, en, n, m;

int main() {
	scanf("%lld%lld", &n, &m);
	for (ll i = 0; i < m; i++) {
		scanf("%lld%lld", &B[i], &P[i]);
		if (i == 0) st = B[i];
		if (i == 1) en = B[i];
		vec[B[i]].push_back(P[i]);
	}
	fill(dist, dist + MAXN, INF);
	pq.push({dist[st] = 0, st});
	while (sz(pq)) {
		ll v = pq.top().S; pq.pop();
		if (mark[v]) continue;
		mark[v] = 1;
		for (ll u : vec[v]) {
			for (ll i = 0, j = v; j >= 0; j -= u, i++) {
				if (dist[j] > dist[v] + i) {
					dist[j] = dist[v] + i;
					pq.push({-dist[j], j});
				}
			}
			for (ll i = 0, j = v; j < n; j += u, i++) {
				if (dist[j] > dist[v] + i) {
					dist[j] = dist[v] + i;
					pq.push({-dist[j], j});
				}
			}
		}
	}
	if (dist[en] == INF) return !printf("-1\n");
	else printf("%lld\n", dist[en]);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%lld%lld", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |   scanf("%lld%lld", &B[i], &P[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 1 ms 1920 KB Output is correct
4 Correct 2 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 3 ms 2048 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 2 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2048 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 1 ms 1920 KB Output is correct
8 Correct 1 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 3 ms 1920 KB Output is correct
13 Correct 3 ms 1920 KB Output is correct
14 Correct 2 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 2 ms 2048 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 6 ms 2048 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 3 ms 2048 KB Output is correct
25 Correct 3 ms 2080 KB Output is correct
26 Correct 5 ms 2048 KB Output is correct
27 Correct 5 ms 2048 KB Output is correct
28 Correct 2 ms 2048 KB Output is correct
29 Correct 3 ms 2176 KB Output is correct
30 Correct 2 ms 2176 KB Output is correct
31 Correct 3 ms 2176 KB Output is correct
32 Correct 2 ms 2176 KB Output is correct
33 Correct 3 ms 2176 KB Output is correct
34 Correct 4 ms 2304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 2 ms 1936 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 2 ms 1920 KB Output is correct
15 Correct 2 ms 2048 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 2 ms 2048 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 6 ms 2048 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 3 ms 2048 KB Output is correct
25 Correct 3 ms 2048 KB Output is correct
26 Correct 5 ms 2048 KB Output is correct
27 Correct 5 ms 2048 KB Output is correct
28 Correct 2 ms 2048 KB Output is correct
29 Correct 3 ms 2176 KB Output is correct
30 Correct 2 ms 2176 KB Output is correct
31 Correct 2 ms 2176 KB Output is correct
32 Correct 2 ms 2176 KB Output is correct
33 Correct 3 ms 2176 KB Output is correct
34 Correct 3 ms 2304 KB Output is correct
35 Correct 10 ms 2944 KB Output is correct
36 Correct 3 ms 2176 KB Output is correct
37 Correct 9 ms 2944 KB Output is correct
38 Correct 13 ms 3328 KB Output is correct
39 Correct 13 ms 3328 KB Output is correct
40 Correct 13 ms 3328 KB Output is correct
41 Correct 12 ms 3328 KB Output is correct
42 Correct 53 ms 2940 KB Output is correct
43 Correct 58 ms 2940 KB Output is correct
44 Correct 53 ms 2940 KB Output is correct
45 Correct 11 ms 3200 KB Output is correct
46 Correct 11 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 2 ms 1952 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 1 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 2 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 2 ms 1920 KB Output is correct
12 Correct 2 ms 1920 KB Output is correct
13 Correct 2 ms 2048 KB Output is correct
14 Correct 2 ms 1920 KB Output is correct
15 Correct 2 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 3 ms 2048 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 6 ms 2048 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 2 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 3 ms 2048 KB Output is correct
25 Correct 4 ms 2048 KB Output is correct
26 Correct 5 ms 2048 KB Output is correct
27 Correct 5 ms 2048 KB Output is correct
28 Correct 2 ms 2048 KB Output is correct
29 Correct 3 ms 2176 KB Output is correct
30 Correct 2 ms 2176 KB Output is correct
31 Correct 3 ms 2176 KB Output is correct
32 Correct 2 ms 2176 KB Output is correct
33 Correct 4 ms 2176 KB Output is correct
34 Correct 4 ms 2304 KB Output is correct
35 Correct 10 ms 2944 KB Output is correct
36 Correct 4 ms 2176 KB Output is correct
37 Correct 9 ms 2944 KB Output is correct
38 Correct 13 ms 3328 KB Output is correct
39 Correct 13 ms 3328 KB Output is correct
40 Correct 13 ms 3328 KB Output is correct
41 Correct 12 ms 3328 KB Output is correct
42 Correct 58 ms 2940 KB Output is correct
43 Correct 57 ms 2940 KB Output is correct
44 Correct 55 ms 2940 KB Output is correct
45 Correct 11 ms 3200 KB Output is correct
46 Correct 12 ms 3200 KB Output is correct
47 Correct 21 ms 4216 KB Output is correct
48 Correct 10 ms 2944 KB Output is correct
49 Correct 9 ms 2944 KB Output is correct
50 Correct 7 ms 2688 KB Output is correct
51 Correct 34 ms 5752 KB Output is correct
52 Correct 34 ms 4732 KB Output is correct
53 Correct 21 ms 4604 KB Output is correct
54 Correct 3 ms 2556 KB Output is correct
55 Correct 4 ms 2556 KB Output is correct
56 Correct 813 ms 4464 KB Output is correct
57 Correct 53 ms 6260 KB Output is correct
58 Correct 948 ms 3372 KB Output is correct
59 Correct 660 ms 3572 KB Output is correct
60 Correct 874 ms 3568 KB Output is correct
61 Correct 644 ms 3564 KB Output is correct
62 Correct 15 ms 3840 KB Output is correct
63 Correct 30 ms 5236 KB Output is correct
64 Correct 32 ms 5116 KB Output is correct
65 Correct 33 ms 5236 KB Output is correct
66 Correct 43 ms 7160 KB Output is correct
67 Correct 44 ms 7160 KB Output is correct