# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1110718 | 2024-11-10T09:12:20 Z | hungnt | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 635 ms | 5748 KB |
#include <bits/stdc++.h> #define BIT(x, k) (((x) >> (k)) & 1) #define on(x, k) ((x) ^ (1ll << (k))) #define pii pair<int, int> #define fi first #define se second #define all(x) x.begin(), x.end() #define ll long long using namespace std; const int N = 50002; int n, m; int a[N]; vector<int> adj[N]; ll dp[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); #define TASK "TASK" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } cin >> n >> m; for(int i = 0, x; i < m; i++) { cin >> a[i] >> x; adj[a[i]].push_back(x); } priority_queue<pii, vector<pii>, greater<pii>> pq; memset(dp, 0x3f, sizeof dp); dp[a[0]] = 0; pq.push({0, a[0]}); while(!pq.empty()) { pii tmp = pq.top();pq.pop(); int u = tmp.se; if(dp[u] != tmp.fi) continue; for(auto &step : adj[u]) { int w = tmp.fi; for(int v = u + step; v < n; v += step) { if (dp[v] > ++w) { dp[v] = w; pq.push({dp[v], v}); } } w = tmp.fi; for(int v = u - step; v >= 0; v -= step) { if (dp[v] > ++w) { dp[v] = w; pq.push({dp[v], v}); } } } } if(dp[a[1]] < dp[n]) cout << dp[a[1]]; else cout << -1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1872 KB | Output is correct |
2 | Correct | 2 ms | 1872 KB | Output is correct |
3 | Correct | 2 ms | 1872 KB | Output is correct |
4 | Correct | 2 ms | 1872 KB | Output is correct |
5 | Correct | 2 ms | 1872 KB | Output is correct |
6 | Correct | 2 ms | 1872 KB | Output is correct |
7 | Correct | 2 ms | 1872 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1872 KB | Output is correct |
2 | Correct | 2 ms | 1872 KB | Output is correct |
3 | Correct | 2 ms | 1872 KB | Output is correct |
4 | Correct | 2 ms | 1872 KB | Output is correct |
5 | Correct | 2 ms | 2040 KB | Output is correct |
6 | Correct | 2 ms | 1872 KB | Output is correct |
7 | Correct | 2 ms | 1872 KB | Output is correct |
8 | Correct | 2 ms | 1872 KB | Output is correct |
9 | Correct | 2 ms | 1872 KB | Output is correct |
10 | Correct | 2 ms | 1872 KB | Output is correct |
11 | Correct | 2 ms | 1884 KB | Output is correct |
12 | Correct | 2 ms | 1872 KB | Output is correct |
13 | Correct | 2 ms | 1872 KB | Output is correct |
14 | Correct | 2 ms | 1872 KB | Output is correct |
15 | Correct | 2 ms | 1872 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1872 KB | Output is correct |
2 | Correct | 2 ms | 1872 KB | Output is correct |
3 | Correct | 2 ms | 1872 KB | Output is correct |
4 | Correct | 2 ms | 1872 KB | Output is correct |
5 | Correct | 2 ms | 1872 KB | Output is correct |
6 | Correct | 2 ms | 2040 KB | Output is correct |
7 | Correct | 2 ms | 1872 KB | Output is correct |
8 | Correct | 2 ms | 1872 KB | Output is correct |
9 | Correct | 2 ms | 1872 KB | Output is correct |
10 | Correct | 2 ms | 1872 KB | Output is correct |
11 | Correct | 2 ms | 1872 KB | Output is correct |
12 | Correct | 2 ms | 1984 KB | Output is correct |
13 | Correct | 2 ms | 1872 KB | Output is correct |
14 | Correct | 2 ms | 1872 KB | Output is correct |
15 | Correct | 2 ms | 1872 KB | Output is correct |
16 | Correct | 2 ms | 1872 KB | Output is correct |
17 | Correct | 4 ms | 1872 KB | Output is correct |
18 | Correct | 2 ms | 1872 KB | Output is correct |
19 | Correct | 2 ms | 1872 KB | Output is correct |
20 | Correct | 5 ms | 2296 KB | Output is correct |
21 | Correct | 2 ms | 1872 KB | Output is correct |
22 | Correct | 3 ms | 1872 KB | Output is correct |
23 | Correct | 2 ms | 1872 KB | Output is correct |
24 | Correct | 3 ms | 1872 KB | Output is correct |
25 | Correct | 2 ms | 2128 KB | Output is correct |
26 | Correct | 4 ms | 1872 KB | Output is correct |
27 | Correct | 4 ms | 1872 KB | Output is correct |
28 | Correct | 2 ms | 1872 KB | Output is correct |
29 | Correct | 3 ms | 2128 KB | Output is correct |
30 | Correct | 3 ms | 2128 KB | Output is correct |
31 | Correct | 3 ms | 2128 KB | Output is correct |
32 | Correct | 2 ms | 2128 KB | Output is correct |
33 | Correct | 4 ms | 2128 KB | Output is correct |
34 | Correct | 3 ms | 2128 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1872 KB | Output is correct |
2 | Correct | 2 ms | 1872 KB | Output is correct |
3 | Correct | 3 ms | 1872 KB | Output is correct |
4 | Correct | 2 ms | 1872 KB | Output is correct |
5 | Correct | 1 ms | 1872 KB | Output is correct |
6 | Correct | 2 ms | 1872 KB | Output is correct |
7 | Correct | 2 ms | 1872 KB | Output is correct |
8 | Correct | 3 ms | 1872 KB | Output is correct |
9 | Correct | 1 ms | 1872 KB | Output is correct |
10 | Correct | 2 ms | 1872 KB | Output is correct |
11 | Correct | 2 ms | 2040 KB | Output is correct |
12 | Correct | 2 ms | 1872 KB | Output is correct |
13 | Correct | 2 ms | 2040 KB | Output is correct |
14 | Correct | 2 ms | 1872 KB | Output is correct |
15 | Correct | 2 ms | 2048 KB | Output is correct |
16 | Correct | 2 ms | 1872 KB | Output is correct |
17 | Correct | 2 ms | 1872 KB | Output is correct |
18 | Correct | 2 ms | 1872 KB | Output is correct |
19 | Correct | 2 ms | 1872 KB | Output is correct |
20 | Correct | 5 ms | 2128 KB | Output is correct |
21 | Correct | 2 ms | 1884 KB | Output is correct |
22 | Correct | 2 ms | 1872 KB | Output is correct |
23 | Correct | 2 ms | 2044 KB | Output is correct |
24 | Correct | 3 ms | 1872 KB | Output is correct |
25 | Correct | 3 ms | 2128 KB | Output is correct |
26 | Correct | 4 ms | 1872 KB | Output is correct |
27 | Correct | 4 ms | 1872 KB | Output is correct |
28 | Correct | 2 ms | 1872 KB | Output is correct |
29 | Correct | 3 ms | 2128 KB | Output is correct |
30 | Correct | 2 ms | 2128 KB | Output is correct |
31 | Correct | 3 ms | 2128 KB | Output is correct |
32 | Correct | 3 ms | 2072 KB | Output is correct |
33 | Correct | 3 ms | 2128 KB | Output is correct |
34 | Correct | 3 ms | 2176 KB | Output is correct |
35 | Correct | 5 ms | 2396 KB | Output is correct |
36 | Correct | 3 ms | 2128 KB | Output is correct |
37 | Correct | 5 ms | 2296 KB | Output is correct |
38 | Correct | 6 ms | 2384 KB | Output is correct |
39 | Correct | 6 ms | 2384 KB | Output is correct |
40 | Correct | 7 ms | 2396 KB | Output is correct |
41 | Correct | 7 ms | 2384 KB | Output is correct |
42 | Correct | 44 ms | 2384 KB | Output is correct |
43 | Correct | 44 ms | 2552 KB | Output is correct |
44 | Correct | 44 ms | 2384 KB | Output is correct |
45 | Correct | 6 ms | 2384 KB | Output is correct |
46 | Correct | 7 ms | 2384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1872 KB | Output is correct |
2 | Correct | 2 ms | 1872 KB | Output is correct |
3 | Correct | 2 ms | 1872 KB | Output is correct |
4 | Correct | 2 ms | 1872 KB | Output is correct |
5 | Correct | 2 ms | 1872 KB | Output is correct |
6 | Correct | 2 ms | 1872 KB | Output is correct |
7 | Correct | 2 ms | 1872 KB | Output is correct |
8 | Correct | 1 ms | 1872 KB | Output is correct |
9 | Correct | 2 ms | 1872 KB | Output is correct |
10 | Correct | 2 ms | 1872 KB | Output is correct |
11 | Correct | 2 ms | 1872 KB | Output is correct |
12 | Correct | 2 ms | 1872 KB | Output is correct |
13 | Correct | 2 ms | 1872 KB | Output is correct |
14 | Correct | 2 ms | 1872 KB | Output is correct |
15 | Correct | 2 ms | 1872 KB | Output is correct |
16 | Correct | 2 ms | 1872 KB | Output is correct |
17 | Correct | 2 ms | 1872 KB | Output is correct |
18 | Correct | 2 ms | 1872 KB | Output is correct |
19 | Correct | 2 ms | 2040 KB | Output is correct |
20 | Correct | 5 ms | 2128 KB | Output is correct |
21 | Correct | 2 ms | 1872 KB | Output is correct |
22 | Correct | 2 ms | 1872 KB | Output is correct |
23 | Correct | 3 ms | 1872 KB | Output is correct |
24 | Correct | 2 ms | 1872 KB | Output is correct |
25 | Correct | 3 ms | 2128 KB | Output is correct |
26 | Correct | 4 ms | 1872 KB | Output is correct |
27 | Correct | 4 ms | 1872 KB | Output is correct |
28 | Correct | 2 ms | 2040 KB | Output is correct |
29 | Correct | 3 ms | 2128 KB | Output is correct |
30 | Correct | 2 ms | 2128 KB | Output is correct |
31 | Correct | 2 ms | 2128 KB | Output is correct |
32 | Correct | 2 ms | 2128 KB | Output is correct |
33 | Correct | 3 ms | 2128 KB | Output is correct |
34 | Correct | 3 ms | 2128 KB | Output is correct |
35 | Correct | 7 ms | 2384 KB | Output is correct |
36 | Correct | 3 ms | 2128 KB | Output is correct |
37 | Correct | 5 ms | 2384 KB | Output is correct |
38 | Correct | 7 ms | 2384 KB | Output is correct |
39 | Correct | 6 ms | 2384 KB | Output is correct |
40 | Correct | 6 ms | 2384 KB | Output is correct |
41 | Correct | 6 ms | 2384 KB | Output is correct |
42 | Correct | 44 ms | 2168 KB | Output is correct |
43 | Correct | 43 ms | 2384 KB | Output is correct |
44 | Correct | 51 ms | 2384 KB | Output is correct |
45 | Correct | 7 ms | 2384 KB | Output is correct |
46 | Correct | 7 ms | 2384 KB | Output is correct |
47 | Correct | 13 ms | 3092 KB | Output is correct |
48 | Correct | 5 ms | 2384 KB | Output is correct |
49 | Correct | 8 ms | 2384 KB | Output is correct |
50 | Correct | 4 ms | 2384 KB | Output is correct |
51 | Correct | 21 ms | 3784 KB | Output is correct |
52 | Correct | 20 ms | 3276 KB | Output is correct |
53 | Correct | 11 ms | 3276 KB | Output is correct |
54 | Correct | 3 ms | 2128 KB | Output is correct |
55 | Correct | 3 ms | 2128 KB | Output is correct |
56 | Correct | 635 ms | 3408 KB | Output is correct |
57 | Correct | 34 ms | 5316 KB | Output is correct |
58 | Correct | 609 ms | 2392 KB | Output is correct |
59 | Correct | 598 ms | 2392 KB | Output is correct |
60 | Correct | 605 ms | 2384 KB | Output is correct |
61 | Correct | 544 ms | 2384 KB | Output is correct |
62 | Correct | 8 ms | 2896 KB | Output is correct |
63 | Correct | 25 ms | 3536 KB | Output is correct |
64 | Correct | 27 ms | 5572 KB | Output is correct |
65 | Correct | 32 ms | 5748 KB | Output is correct |
66 | Correct | 43 ms | 5316 KB | Output is correct |
67 | Correct | 48 ms | 5572 KB | Output is correct |