# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1110724 | 2024-11-10T09:22:34 Z | hungnt | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 463 ms | 5576 KB |
#pragma GCC optimize("O3") #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(int &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
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2040 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 | 2 ms | 1872 KB | Output is correct |
9 | Correct | 2 ms | 1868 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 | 3 ms | 1872 KB | Output is correct |
14 | Correct | 2 ms | 1872 KB | Output is correct |
15 | Correct | 2 ms | 1872 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 1872 KB | Output is correct |
13 | Correct | 3 ms | 1872 KB | Output is correct |
14 | Correct | 2 ms | 2036 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 | 3 ms | 1872 KB | Output is correct |
19 | Correct | 2 ms | 1872 KB | Output is correct |
20 | Correct | 4 ms | 2128 KB | Output is correct |
21 | Correct | 2 ms | 2036 KB | Output is correct |
22 | Correct | 2 ms | 1872 KB | Output is correct |
23 | Correct | 2 ms | 1872 KB | Output is correct |
24 | Correct | 2 ms | 1872 KB | Output is correct |
25 | Correct | 3 ms | 2296 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 | 2168 KB | Output is correct |
30 | Correct | 3 ms | 2128 KB | Output is correct |
31 | Correct | 2 ms | 2128 KB | Output is correct |
32 | Correct | 2 ms | 2296 KB | Output is correct |
33 | Correct | 3 ms | 2128 KB | Output is correct |
34 | Correct | 3 ms | 2128 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2044 KB | Output is correct |
2 | Correct | 2 ms | 1872 KB | Output is correct |
3 | Correct | 2 ms | 2040 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 | 1872 KB | Output is correct |
13 | Correct | 2 ms | 1864 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 | 1872 KB | Output is correct |
20 | Correct | 4 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 | 2 ms | 2040 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 | 4 ms | 2384 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 | 2128 KB | Output is correct |
33 | Correct | 3 ms | 2280 KB | Output is correct |
34 | Correct | 4 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 | 2552 KB | Output is correct |
38 | Correct | 6 ms | 2552 KB | Output is correct |
39 | Correct | 7 ms | 2384 KB | Output is correct |
40 | Correct | 7 ms | 2384 KB | Output is correct |
41 | Correct | 7 ms | 2384 KB | Output is correct |
42 | Correct | 38 ms | 2384 KB | Output is correct |
43 | Correct | 35 ms | 2384 KB | Output is correct |
44 | Correct | 34 ms | 2384 KB | Output is correct |
45 | Correct | 7 ms | 2556 KB | Output is correct |
46 | Correct | 7 ms | 2556 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1872 KB | Output is correct |
2 | Correct | 2 ms | 2132 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 | 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 | 3 ms | 1872 KB | Output is correct |
12 | Correct | 2 ms | 1872 KB | Output is correct |
13 | Correct | 2 ms | 2036 KB | Output is correct |
14 | Correct | 2 ms | 2064 KB | Output is correct |
15 | Correct | 2 ms | 2040 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 | 4 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 | 2 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 | 2056 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 | 2144 KB | Output is correct |
31 | Correct | 3 ms | 2128 KB | Output is correct |
32 | Correct | 3 ms | 2128 KB | Output is correct |
33 | Correct | 4 ms | 2128 KB | Output is correct |
34 | Correct | 4 ms | 2128 KB | Output is correct |
35 | Correct | 9 ms | 2384 KB | Output is correct |
36 | Correct | 3 ms | 2128 KB | Output is correct |
37 | Correct | 5 ms | 2360 KB | Output is correct |
38 | Correct | 6 ms | 2288 KB | Output is correct |
39 | Correct | 7 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 | 34 ms | 2384 KB | Output is correct |
43 | Correct | 33 ms | 2520 KB | Output is correct |
44 | Correct | 34 ms | 2384 KB | Output is correct |
45 | Correct | 6 ms | 2384 KB | Output is correct |
46 | Correct | 9 ms | 2384 KB | Output is correct |
47 | Correct | 13 ms | 3020 KB | Output is correct |
48 | Correct | 5 ms | 2384 KB | Output is correct |
49 | Correct | 5 ms | 2384 KB | Output is correct |
50 | Correct | 5 ms | 2264 KB | Output is correct |
51 | Correct | 22 ms | 3784 KB | Output is correct |
52 | Correct | 19 ms | 3444 KB | Output is correct |
53 | Correct | 12 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 | 463 ms | 3408 KB | Output is correct |
57 | Correct | 33 ms | 5316 KB | Output is correct |
58 | Correct | 452 ms | 2384 KB | Output is correct |
59 | Correct | 458 ms | 2384 KB | Output is correct |
60 | Correct | 446 ms | 2396 KB | Output is correct |
61 | Correct | 396 ms | 2384 KB | Output is correct |
62 | Correct | 8 ms | 2908 KB | Output is correct |
63 | Correct | 23 ms | 3536 KB | Output is correct |
64 | Correct | 24 ms | 5572 KB | Output is correct |
65 | Correct | 31 ms | 5576 KB | Output is correct |
66 | Correct | 43 ms | 5392 KB | Output is correct |
67 | Correct | 46 ms | 5572 KB | Output is correct |