Task: | Ladders |
Sender: | aalto2024g_001 |
Submission time: | 2024-10-09 17:46:47 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | RUNTIME ERROR | 0.00 s | details |
#2 | RUNTIME ERROR | 0.00 s | details |
#3 | RUNTIME ERROR | 0.00 s | details |
#4 | RUNTIME ERROR | 0.00 s | details |
#5 | RUNTIME ERROR | 0.00 s | details |
#6 | RUNTIME ERROR | 0.00 s | details |
#7 | RUNTIME ERROR | 0.00 s | details |
#8 | RUNTIME ERROR | 0.00 s | details |
#9 | RUNTIME ERROR | 0.00 s | details |
#10 | RUNTIME ERROR | 0.00 s | details |
#11 | RUNTIME ERROR | 0.00 s | details |
#12 | RUNTIME ERROR | 0.00 s | details |
#13 | RUNTIME ERROR | 0.00 s | details |
#14 | RUNTIME ERROR | 0.00 s | details |
#15 | RUNTIME ERROR | 0.00 s | details |
#16 | RUNTIME ERROR | 0.00 s | details |
#17 | RUNTIME ERROR | 0.00 s | details |
#18 | RUNTIME ERROR | 0.00 s | details |
#19 | RUNTIME ERROR | 0.00 s | details |
#20 | RUNTIME ERROR | 0.00 s | details |
#21 | RUNTIME ERROR | 0.00 s | details |
#22 | RUNTIME ERROR | 0.00 s | details |
#23 | RUNTIME ERROR | 0.00 s | details |
#24 | RUNTIME ERROR | 0.00 s | details |
#25 | RUNTIME ERROR | 0.00 s | details |
#26 | RUNTIME ERROR | 0.00 s | details |
#27 | RUNTIME ERROR | 0.00 s | details |
#28 | RUNTIME ERROR | 0.00 s | details |
#29 | RUNTIME ERROR | 0.00 s | details |
#30 | RUNTIME ERROR | 0.00 s | details |
#31 | RUNTIME ERROR | 0.00 s | details |
#32 | RUNTIME ERROR | 0.00 s | details |
#33 | RUNTIME ERROR | 0.00 s | details |
#34 | RUNTIME ERROR | 0.00 s | details |
#35 | RUNTIME ERROR | 0.00 s | details |
#36 | RUNTIME ERROR | 0.00 s | details |
#37 | RUNTIME ERROR | 0.00 s | details |
#38 | RUNTIME ERROR | 0.00 s | details |
#39 | RUNTIME ERROR | 0.00 s | details |
#40 | RUNTIME ERROR | 0.00 s | details |
#41 | RUNTIME ERROR | 0.00 s | details |
#42 | RUNTIME ERROR | 0.00 s | details |
#43 | RUNTIME ERROR | 0.00 s | details |
#44 | RUNTIME ERROR | 0.00 s | details |
#45 | RUNTIME ERROR | 0.00 s | details |
#46 | RUNTIME ERROR | 0.00 s | details |
#47 | RUNTIME ERROR | 0.00 s | details |
#48 | RUNTIME ERROR | 0.00 s | details |
#49 | RUNTIME ERROR | 0.00 s | details |
#50 | RUNTIME ERROR | 0.00 s | details |
#51 | RUNTIME ERROR | 0.00 s | details |
#52 | RUNTIME ERROR | 0.01 s | details |
#53 | RUNTIME ERROR | 0.00 s | details |
#54 | RUNTIME ERROR | 0.00 s | details |
#55 | RUNTIME ERROR | 0.00 s | details |
#56 | RUNTIME ERROR | 0.00 s | details |
#57 | RUNTIME ERROR | 0.00 s | details |
#58 | RUNTIME ERROR | 0.00 s | details |
#59 | RUNTIME ERROR | 0.00 s | details |
#60 | RUNTIME ERROR | 0.00 s | details |
#61 | RUNTIME ERROR | 0.00 s | details |
#62 | WRONG ANSWER | 0.10 s | details |
#63 | ACCEPTED | 0.10 s | details |
#64 | WRONG ANSWER | 0.10 s | details |
#65 | WRONG ANSWER | 0.10 s | details |
#66 | WRONG ANSWER | 0.08 s | details |
#67 | ACCEPTED | 0.10 s | details |
#68 | ACCEPTED | 0.07 s | details |
#69 | ACCEPTED | 0.10 s | details |
#70 | ACCEPTED | 0.12 s | details |
#71 | ACCEPTED | 0.10 s | details |
Code
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <numeric> #include <unordered_map> #include <queue> #include <climits> #include <cmath> #define int long long using namespace std; void solve() { int n; cin >> n; vector<int> nums(n); vector<int> inds(n); vector<vector<int>> adj(n, vector<int>()); for (int i = 0; i < n; i++) { cin >> nums[i]; inds[nums[i]] = i; } for (int i = 0; i < n; i++) { int val = nums[i]; adj[i].push_back(i+1); for (int j = 2*val; j <= n; j += val) { adj[i].push_back(inds[j]); } } priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; vector<int> dist(adj.size()+1, LLONG_MAX); vector<int> next(adj.size()+1, 0); vector<int> visited(adj.size()+1, false); pq.push({0, 1}); dist[1] = 0; while (!pq.empty()) { int u = pq.top().second; pq.pop(); if (visited[u]) continue; visited[u] = true; // Iterate through all adjacent vertices of the current vertex for (auto &neighbor : adj[u]) { int v = neighbor; int weight = 1; // If a shorter path to v is found if (!visited[v] && dist[v] > dist[u] + weight) { // Update distance and push new distance to the priority queue dist[v] = dist[u] + weight; next[u] = v; pq.push({dist[v], v}); } } } /* int curr = 1; while (curr != n) { cout << curr << " "; curr = next[curr]; } */ cout << dist[n]; } signed main() { int t = 1; //cin >> t; for (int i = 0; i < t; i++) solve(); return 0; }
Test details
Test 1
Verdict: RUNTIME ERROR
input |
---|
1 1 |
correct output |
---|
0 |
user output |
---|
(empty) |
Test 2
Verdict: RUNTIME ERROR
input |
---|
2 2 1 |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 3
Verdict: RUNTIME ERROR
input |
---|
2 1 2 |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 4
Verdict: RUNTIME ERROR
input |
---|
2 2 1 |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 5
Verdict: RUNTIME ERROR
input |
---|
3 2 3 1 |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 6
Verdict: RUNTIME ERROR
input |
---|
3 1 2 3 |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 7
Verdict: RUNTIME ERROR
input |
---|
3 3 2 1 |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 8
Verdict: RUNTIME ERROR
input |
---|
4 3 2 1 4 |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 9
Verdict: RUNTIME ERROR
input |
---|
4 4 3 2 1 |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 10
Verdict: RUNTIME ERROR
input |
---|
4 4 2 1 3 |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 11
Verdict: RUNTIME ERROR
input |
---|
4 3 2 1 4 |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 12
Verdict: RUNTIME ERROR
input |
---|
4 1 3 2 4 |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 13
Verdict: RUNTIME ERROR
input |
---|
5 3 2 4 1 5 |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 14
Verdict: RUNTIME ERROR
input |
---|
5 1 2 4 3 5 |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 15
Verdict: RUNTIME ERROR
input |
---|
5 5 3 1 2 4 |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 16
Verdict: RUNTIME ERROR
input |
---|
5 3 1 4 2 5 |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 17
Verdict: RUNTIME ERROR
input |
---|
5 1 2 3 4 5 |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 18
Verdict: RUNTIME ERROR
input |
---|
5 3 1 5 4 2 |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 19
Verdict: RUNTIME ERROR
input |
---|
5 5 4 3 2 1 |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 20
Verdict: RUNTIME ERROR
input |
---|
5 5 3 1 4 2 |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 21
Verdict: RUNTIME ERROR
input |
---|
5 5 4 3 2 1 |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 22
Verdict: RUNTIME ERROR
input |
---|
5 5 1 4 3 2 |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 23
Verdict: RUNTIME ERROR
input |
---|
10 4 8 3 1 7 2 5 10 6 9 |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 24
Verdict: RUNTIME ERROR
input |
---|
10 8 10 3 6 5 1 4 7 2 9 |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 25
Verdict: RUNTIME ERROR
input |
---|
10 4 1 2 7 5 10 8 6 9 3 |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 26
Verdict: RUNTIME ERROR
input |
---|
10 10 9 7 2 5 1 3 4 6 8 |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 27
Verdict: RUNTIME ERROR
input |
---|
10 1 2 3 4 5 6 7 8 9 10 |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 28
Verdict: RUNTIME ERROR
input |
---|
10 6 7 10 9 5 2 1 3 8 4 |
correct output |
---|
6 |
user output |
---|
(empty) |
Test 29
Verdict: RUNTIME ERROR
input |
---|
10 10 9 8 7 6 5 4 3 2 1 |
correct output |
---|
9 |
user output |
---|
(empty) |
Test 30
Verdict: RUNTIME ERROR
input |
---|
10 8 5 3 7 4 1 6 2 10 9 |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 31
Verdict: RUNTIME ERROR
input |
---|
10 10 9 8 7 6 5 4 3 2 1 |
correct output |
---|
9 |
user output |
---|
(empty) |
Test 32
Verdict: RUNTIME ERROR
input |
---|
10 10 3 6 8 4 5 1 7 2 9 |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 33
Verdict: RUNTIME ERROR
input |
---|
100 14 63 92 70 7 59 86 25 60 9 73... |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 34
Verdict: RUNTIME ERROR
input |
---|
100 92 55 15 16 23 1 24 22 89 71 6... |
correct output |
---|
6 |
user output |
---|
(empty) |
Test 35
Verdict: RUNTIME ERROR
input |
---|
100 34 58 2 29 82 83 47 100 91 35 ... |
correct output |
---|
3 |
user output |
---|
(empty) |
Test 36
Verdict: RUNTIME ERROR
input |
---|
100 26 63 34 33 58 41 40 29 22 8 7... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 37
Verdict: RUNTIME ERROR
input |
---|
100 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 38
Verdict: RUNTIME ERROR
input |
---|
100 6 85 10 52 5 84 64 92 89 31 60... |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 39
Verdict: RUNTIME ERROR
input |
---|
100 100 99 98 97 96 95 94 93 92 91... |
correct output |
---|
99 |
user output |
---|
(empty) |
Test 40
Verdict: RUNTIME ERROR
input |
---|
100 33 75 25 88 30 21 6 11 72 70 3... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 41
Verdict: RUNTIME ERROR
input |
---|
100 30 86 34 36 29 12 39 7 65 23 3... |
correct output |
---|
8 |
user output |
---|
(empty) |
Test 42
Verdict: RUNTIME ERROR
input |
---|
200 14 63 135 70 7 59 198 180 108 ... |
correct output |
---|
6 |
user output |
---|
(empty) |
Test 43
Verdict: RUNTIME ERROR
input |
---|
200 92 55 151 199 107 153 113 22 1... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 44
Verdict: RUNTIME ERROR
input |
---|
200 34 58 2 29 82 162 47 100 91 35... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 45
Verdict: RUNTIME ERROR
input |
---|
200 148 63 188 153 170 41 180 112 ... |
correct output |
---|
9 |
user output |
---|
(empty) |
Test 46
Verdict: RUNTIME ERROR
input |
---|
200 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 47
Verdict: RUNTIME ERROR
input |
---|
200 175 162 119 135 5 84 180 92 89... |
correct output |
---|
8 |
user output |
---|
(empty) |
Test 48
Verdict: RUNTIME ERROR
input |
---|
200 200 199 198 197 196 195 194 19... |
correct output |
---|
199 |
user output |
---|
(empty) |
Test 49
Verdict: RUNTIME ERROR
input |
---|
200 160 75 25 88 30 21 6 11 72 70 ... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 50
Verdict: RUNTIME ERROR
input |
---|
200 30 86 162 36 29 12 145 195 134... |
correct output |
---|
4 |
user output |
---|
(empty) |
Test 51
Verdict: RUNTIME ERROR
input |
---|
200 47 121 66 36 23 37 113 151 60 ... |
correct output |
---|
6 |
user output |
---|
(empty) |
Test 52
Verdict: RUNTIME ERROR
input |
---|
1000 934 460 976 361 744 297 198 66... |
correct output |
---|
12 |
user output |
---|
(empty) |
Test 53
Verdict: RUNTIME ERROR
input |
---|
1000 999 410 151 405 349 770 809 59... |
correct output |
---|
12 |
user output |
---|
(empty) |
Test 54
Verdict: RUNTIME ERROR
input |
---|
1000 505 953 714 811 82 503 751 709... |
correct output |
---|
9 |
user output |
---|
(empty) |
Test 55
Verdict: RUNTIME ERROR
input |
---|
1000 960 63 254 153 973 296 180 300... |
correct output |
---|
6 |
user output |
---|
(empty) |
Test 56
Verdict: RUNTIME ERROR
input |
---|
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
1 |
user output |
---|
(empty) |
Test 57
Verdict: RUNTIME ERROR
input |
---|
1000 919 660 119 418 355 220 207 38... |
correct output |
---|
8 |
user output |
---|
(empty) |
Test 58
Verdict: RUNTIME ERROR
input |
---|
1000 1000 999 998 997 996 995 994 9... |
correct output |
---|
999 |
user output |
---|
(empty) |
Test 59
Verdict: RUNTIME ERROR
input |
---|
1000 219 802 25 833 912 846 639 806... |
correct output |
---|
5 |
user output |
---|
(empty) |
Test 60
Verdict: RUNTIME ERROR
input |
---|
1000 821 625 397 588 943 372 469 30... |
correct output |
---|
15 |
user output |
---|
(empty) |
Test 61
Verdict: RUNTIME ERROR
input |
---|
1000 749 481 66 36 256 37 113 712 5... |
correct output |
---|
10 |
user output |
---|
(empty) |
Test 62
Verdict: WRONG ANSWER
input |
---|
100000 26990 68204 21904 3028 29287 1... |
correct output |
---|
8 |
user output |
---|
9 |
Test 63
Verdict: ACCEPTED
input |
---|
100000 94616 96638 65840 9893 92126 1... |
correct output |
---|
12 |
user output |
---|
12 |
Test 64
Verdict: WRONG ANSWER
input |
---|
100000 11080 90273 56653 73314 33646 ... |
correct output |
---|
10 |
user output |
---|
16 |
Test 65
Verdict: WRONG ANSWER
input |
---|
100000 27548 48776 71938 59265 12094 ... |
correct output |
---|
11 |
user output |
---|
13 |
Test 66
Verdict: WRONG ANSWER
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
1 |
user output |
---|
2 |
Test 67
Verdict: ACCEPTED
input |
---|
100000 77221 89614 36710 27644 37101 ... |
correct output |
---|
11 |
user output |
---|
11 |
Test 68
Verdict: ACCEPTED
input |
---|
100000 100000 99999 99998 99997 99996... |
correct output |
---|
99999 |
user output |
---|
99999 |
Test 69
Verdict: ACCEPTED
input |
---|
100000 68737 37819 55518 77756 46481 ... |
correct output |
---|
12 |
user output |
---|
12 |
Test 70
Verdict: ACCEPTED
input |
---|
100000 39437 53659 60243 20923 38668 ... |
correct output |
---|
11 |
user output |
---|
11 |
Test 71
Verdict: ACCEPTED
input |
---|
100000 69631 70212 62831 61461 93551 ... |
correct output |
---|
14 |
user output |
---|
14 |