Submission #960470

# Submission time Handle Problem Language Result Execution time Memory
960470 2024-04-10T14:03:31 Z Blagoj Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 49980 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
 
const int mxn = 30010;
 
int n, m;
map<int, ll> best[mxn];
vector<int> val[mxn];
int spot[mxn], jump[mxn];
int dx[] = {-1, 1};
 
void solve() {
    priority_queue<pair<ll, pair<int, int>>> pq;
    pq.push({0, {spot[0], jump[0]}});
    best[spot[0]][jump[0]] = 0;
    while (pq.size()) {
        ll dist = -pq.top().first, pos = pq.top().second.first, pwr = pq.top().second.second;
        pq.pop();
        for (auto x : val[pos]) {
            if (!best[pos].count(jump[x])) best[pos][jump[x]] = 1e18; 
            if (dist < best[pos][jump[x]]) {
                best[pos][jump[x]] = dist;
                pq.push({-dist, {pos, jump[x]}});
            }
        }
        for (int d = 0; d < 2; d++) {
            int newPos = pos + pwr * dx[d];
            if (0 <= newPos && newPos < n) {
                if (!best[newPos].count(pwr)) best[newPos][pwr] = 1e18; 
                if (dist + 1 < best[newPos][pwr]) {
                    best[newPos][pwr] = dist + 1;
                    pq.push({-best[newPos][pwr], {newPos, pwr}});
                }
            }
        }
    }
    ll ans = 1e18;
    for (auto x : best[spot[1]]) ans = min(ans, x.second);
    cout << (ans != 1e18 ? ans : -1);
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> spot[i] >> jump[i];
        val[spot[i]].push_back(i);
    }
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2888 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 4 ms 2908 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 5 ms 2908 KB Output is correct
15 Correct 8 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 6 ms 2784 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 5 ms 2908 KB Output is correct
15 Correct 5 ms 2908 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 11 ms 3420 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 2 ms 2648 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 3188 KB Output is correct
24 Correct 5 ms 3420 KB Output is correct
25 Correct 3 ms 2972 KB Output is correct
26 Correct 2 ms 3164 KB Output is correct
27 Correct 6 ms 2900 KB Output is correct
28 Correct 8 ms 4144 KB Output is correct
29 Correct 19 ms 6492 KB Output is correct
30 Correct 4 ms 3676 KB Output is correct
31 Correct 10 ms 4696 KB Output is correct
32 Correct 7 ms 4080 KB Output is correct
33 Correct 36 ms 10192 KB Output is correct
34 Correct 39 ms 10024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 2792 KB Output is correct
11 Correct 6 ms 2908 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 6 ms 2908 KB Output is correct
15 Correct 5 ms 2908 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 7 ms 3420 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2696 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 3 ms 2904 KB Output is correct
24 Correct 6 ms 3420 KB Output is correct
25 Correct 3 ms 3164 KB Output is correct
26 Correct 2 ms 3164 KB Output is correct
27 Correct 5 ms 2968 KB Output is correct
28 Correct 6 ms 3928 KB Output is correct
29 Correct 16 ms 6300 KB Output is correct
30 Correct 5 ms 3656 KB Output is correct
31 Correct 9 ms 4696 KB Output is correct
32 Correct 6 ms 3932 KB Output is correct
33 Correct 43 ms 10376 KB Output is correct
34 Correct 38 ms 10064 KB Output is correct
35 Correct 109 ms 9772 KB Output is correct
36 Correct 9 ms 3664 KB Output is correct
37 Correct 200 ms 14032 KB Output is correct
38 Correct 161 ms 13512 KB Output is correct
39 Correct 159 ms 13512 KB Output is correct
40 Correct 186 ms 13452 KB Output is correct
41 Correct 178 ms 13484 KB Output is correct
42 Correct 7 ms 3420 KB Output is correct
43 Correct 64 ms 3420 KB Output is correct
44 Correct 4 ms 3164 KB Output is correct
45 Correct 435 ms 33636 KB Output is correct
46 Correct 437 ms 33580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2640 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2628 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 4 ms 2908 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2660 KB Output is correct
14 Correct 5 ms 2904 KB Output is correct
15 Correct 5 ms 3028 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 7 ms 3420 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2908 KB Output is correct
24 Correct 5 ms 3412 KB Output is correct
25 Correct 3 ms 3164 KB Output is correct
26 Correct 3 ms 3160 KB Output is correct
27 Correct 6 ms 2908 KB Output is correct
28 Correct 6 ms 3928 KB Output is correct
29 Correct 18 ms 6276 KB Output is correct
30 Correct 4 ms 3636 KB Output is correct
31 Correct 10 ms 4652 KB Output is correct
32 Correct 7 ms 3932 KB Output is correct
33 Correct 40 ms 9988 KB Output is correct
34 Correct 40 ms 10200 KB Output is correct
35 Correct 110 ms 9752 KB Output is correct
36 Correct 9 ms 3920 KB Output is correct
37 Correct 194 ms 13976 KB Output is correct
38 Correct 190 ms 13596 KB Output is correct
39 Correct 192 ms 13592 KB Output is correct
40 Correct 187 ms 13532 KB Output is correct
41 Correct 171 ms 13536 KB Output is correct
42 Correct 8 ms 3572 KB Output is correct
43 Correct 70 ms 3412 KB Output is correct
44 Correct 4 ms 3168 KB Output is correct
45 Correct 420 ms 33628 KB Output is correct
46 Correct 429 ms 33656 KB Output is correct
47 Correct 867 ms 49980 KB Output is correct
48 Correct 6 ms 3416 KB Output is correct
49 Correct 4 ms 3420 KB Output is correct
50 Correct 3 ms 3228 KB Output is correct
51 Correct 161 ms 23444 KB Output is correct
52 Correct 202 ms 25504 KB Output is correct
53 Correct 20 ms 9308 KB Output is correct
54 Correct 2 ms 3416 KB Output is correct
55 Correct 3 ms 4188 KB Output is correct
56 Correct 8 ms 5724 KB Output is correct
57 Correct 167 ms 29780 KB Output is correct
58 Correct 12 ms 7004 KB Output is correct
59 Correct 14 ms 9052 KB Output is correct
60 Correct 23 ms 10832 KB Output is correct
61 Execution timed out 1028 ms 9760 KB Time limit exceeded
62 Halted 0 ms 0 KB -