Submission #539043

# Submission time Handle Problem Language Result Execution time Memory
539043 2022-03-18T10:26:35 Z SlavicG Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 16020 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int N = 3e5 + 10;
vector<pair<int, int>> adj[N];
vector<int> dog[N];
void solve() {
    int n, m; cin >> n >> m;
    vector<int> b(m), p(m);
    for(int i = 0;i < m; ++i) {
        cin >> b[i] >> p[i];
        dog[b[i]].pb(i);
    } 
    priority_queue<pair<int,int>> q;

    vector<int> dist(m, INT_MAX);
    dist[0] = 0;
    q.push({0, 0});

    while(!q.empty()) {
        int u = q.top().second;
        q.pop();

        int pp = b[u];
        int jumps = 0;

        for(int v: dog[pp]) {
            if(dist[v] > dist[u] + jumps) {
                dist[v] = dist[u] + jumps;
                q.push({-dist[v], v});
            }
        }

        while(pp + p[u] < n) {
            pp += p[u];
            ++jumps;
            for(int v: dog[pp]) {
                if(dist[v] > dist[u] + jumps) {
                    dist[v] = dist[u] + jumps;
                    q.push({-dist[v], v});
                }
                break;
            }
        }
        pp = b[u], jumps = 0;
        while(pp - p[u] >= 0) {
            pp -= p[u];
            ++jumps;
            for(int v: dog[pp]) {
                if(dist[v] > dist[u] + jumps) {
                    dist[v] = dist[u] + jumps;
                    q.push({-dist[v], v});
                }
                break;
            }
        }
    }

    if(dist[1] == INT_MAX) cout << "-1\n";
    else
    cout << dist[1] << "\n";
}

 
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14292 KB Output is correct
2 Correct 7 ms 14292 KB Output is correct
3 Correct 7 ms 14292 KB Output is correct
4 Correct 8 ms 14404 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 7 ms 14380 KB Output is correct
7 Correct 9 ms 14292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14300 KB Output is correct
2 Correct 9 ms 14292 KB Output is correct
3 Correct 9 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 7 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 7 ms 14292 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 12 ms 14476 KB Output is correct
13 Correct 11 ms 14412 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14368 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 8 ms 14388 KB Output is correct
4 Correct 9 ms 14292 KB Output is correct
5 Correct 9 ms 14292 KB Output is correct
6 Correct 8 ms 14292 KB Output is correct
7 Correct 9 ms 14296 KB Output is correct
8 Correct 8 ms 14336 KB Output is correct
9 Correct 9 ms 14292 KB Output is correct
10 Correct 8 ms 14292 KB Output is correct
11 Correct 10 ms 14420 KB Output is correct
12 Correct 12 ms 14420 KB Output is correct
13 Correct 14 ms 14420 KB Output is correct
14 Correct 10 ms 14420 KB Output is correct
15 Correct 9 ms 14436 KB Output is correct
16 Correct 8 ms 14408 KB Output is correct
17 Correct 10 ms 14420 KB Output is correct
18 Correct 8 ms 14420 KB Output is correct
19 Correct 8 ms 14416 KB Output is correct
20 Correct 18 ms 14528 KB Output is correct
21 Correct 8 ms 14420 KB Output is correct
22 Correct 8 ms 14420 KB Output is correct
23 Correct 8 ms 14352 KB Output is correct
24 Correct 10 ms 14420 KB Output is correct
25 Correct 9 ms 14420 KB Output is correct
26 Correct 18 ms 14420 KB Output is correct
27 Correct 15 ms 14420 KB Output is correct
28 Correct 8 ms 14420 KB Output is correct
29 Correct 8 ms 14420 KB Output is correct
30 Correct 8 ms 14292 KB Output is correct
31 Correct 10 ms 14332 KB Output is correct
32 Correct 8 ms 14408 KB Output is correct
33 Correct 8 ms 14420 KB Output is correct
34 Correct 8 ms 14440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 8 ms 14364 KB Output is correct
4 Correct 8 ms 14292 KB Output is correct
5 Correct 7 ms 14292 KB Output is correct
6 Correct 8 ms 14292 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 8 ms 14292 KB Output is correct
9 Correct 9 ms 14292 KB Output is correct
10 Correct 8 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 12 ms 14388 KB Output is correct
13 Correct 14 ms 14420 KB Output is correct
14 Correct 9 ms 14420 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14484 KB Output is correct
18 Correct 8 ms 14360 KB Output is correct
19 Correct 8 ms 14324 KB Output is correct
20 Correct 18 ms 14532 KB Output is correct
21 Correct 8 ms 14420 KB Output is correct
22 Correct 7 ms 14420 KB Output is correct
23 Correct 10 ms 14420 KB Output is correct
24 Correct 9 ms 14444 KB Output is correct
25 Correct 8 ms 14420 KB Output is correct
26 Correct 15 ms 14484 KB Output is correct
27 Correct 15 ms 14480 KB Output is correct
28 Correct 8 ms 14420 KB Output is correct
29 Correct 8 ms 14316 KB Output is correct
30 Correct 8 ms 14292 KB Output is correct
31 Correct 8 ms 14420 KB Output is correct
32 Correct 9 ms 14320 KB Output is correct
33 Correct 9 ms 14420 KB Output is correct
34 Correct 9 ms 14420 KB Output is correct
35 Correct 18 ms 14996 KB Output is correct
36 Correct 12 ms 14548 KB Output is correct
37 Correct 16 ms 14804 KB Output is correct
38 Correct 22 ms 15080 KB Output is correct
39 Correct 19 ms 15060 KB Output is correct
40 Correct 18 ms 15060 KB Output is correct
41 Correct 19 ms 15060 KB Output is correct
42 Correct 886 ms 15188 KB Output is correct
43 Correct 895 ms 15188 KB Output is correct
44 Correct 922 ms 15228 KB Output is correct
45 Correct 21 ms 14988 KB Output is correct
46 Correct 21 ms 14996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14292 KB Output is correct
2 Correct 7 ms 14340 KB Output is correct
3 Correct 8 ms 14292 KB Output is correct
4 Correct 7 ms 14292 KB Output is correct
5 Correct 9 ms 14292 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 8 ms 14292 KB Output is correct
9 Correct 10 ms 14344 KB Output is correct
10 Correct 9 ms 14420 KB Output is correct
11 Correct 9 ms 14420 KB Output is correct
12 Correct 13 ms 14420 KB Output is correct
13 Correct 11 ms 14420 KB Output is correct
14 Correct 9 ms 14420 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 9 ms 14420 KB Output is correct
18 Correct 8 ms 14448 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 19 ms 14532 KB Output is correct
21 Correct 10 ms 14420 KB Output is correct
22 Correct 8 ms 14420 KB Output is correct
23 Correct 8 ms 14360 KB Output is correct
24 Correct 8 ms 14420 KB Output is correct
25 Correct 9 ms 14420 KB Output is correct
26 Correct 17 ms 14456 KB Output is correct
27 Correct 20 ms 14476 KB Output is correct
28 Correct 10 ms 14420 KB Output is correct
29 Correct 8 ms 14432 KB Output is correct
30 Correct 8 ms 14292 KB Output is correct
31 Correct 8 ms 14420 KB Output is correct
32 Correct 8 ms 14420 KB Output is correct
33 Correct 8 ms 14420 KB Output is correct
34 Correct 9 ms 14380 KB Output is correct
35 Correct 16 ms 15004 KB Output is correct
36 Correct 9 ms 14516 KB Output is correct
37 Correct 16 ms 14832 KB Output is correct
38 Correct 19 ms 15044 KB Output is correct
39 Correct 18 ms 15128 KB Output is correct
40 Correct 19 ms 15060 KB Output is correct
41 Correct 18 ms 15076 KB Output is correct
42 Correct 869 ms 15188 KB Output is correct
43 Correct 860 ms 15188 KB Output is correct
44 Correct 856 ms 15232 KB Output is correct
45 Correct 20 ms 14932 KB Output is correct
46 Correct 19 ms 14992 KB Output is correct
47 Correct 35 ms 15656 KB Output is correct
48 Correct 12 ms 15072 KB Output is correct
49 Correct 13 ms 15088 KB Output is correct
50 Correct 12 ms 14932 KB Output is correct
51 Correct 35 ms 15976 KB Output is correct
52 Correct 34 ms 15992 KB Output is correct
53 Correct 21 ms 15700 KB Output is correct
54 Correct 8 ms 14292 KB Output is correct
55 Correct 8 ms 14300 KB Output is correct
56 Execution timed out 1095 ms 16020 KB Time limit exceeded
57 Halted 0 ms 0 KB -