Submission #583031

# Submission time Handle Problem Language Result Execution time Memory
583031 2022-06-24T17:46:31 Z gg123_pe Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
161 ms 59632 KB
#include <bits/stdc++.h>
using namespace std; 

typedef long long ll; 
typedef pair<ll,ll> ii; 

#define f(i,a,b) for(ll i = a; i < b; i++)
#define fa(i,a,b) for(ll i = a; i >= b; i--)

const int N = 30005; 
const ll inf = 1e18;


int n, m, b[N];
ll p[N], d[N];
 
vector <pair<ll,ll>> adj[N], v[N];
set <int> s[N]; 

void dij(int x){
    f(i,0,m) d[i] = inf; 
    d[x] = 0; 

    priority_queue <ii, vector <ii>, greater<ii>> q; 
    q.push({0, x}); 

    while(!q.empty()){
        ii p = q.top(); 
        q.pop(); 

        ll d_v = p.first, v = p.second; 

        if(d_v != d[v]) continue; 

        for(auto wi: adj[v]){
            ll u = wi.first, w = wi.second; 
            if(d[u] > d[v] + w){
                d[u] = d[v] + w; 
                q.push({d[u], u}); 
            }
        }
    }
}
int main(){
    cin >> n >> m; 

    f(i,0,m){
        cin >> b[i] >> p[i]; 
    
        s[b[i]].insert(p[i]); 
        v[b[i]].push_back({p[i], i}); 
    }

    f(i,0,n){
        int l = v[i].size(); 
        f(j,0,l){
            adj[v[i][j].second].push_back({v[i][(j+1)%l].second, 0}); 
        }
    }

    f(i,0,n){
        map <int, bool> us; 

        for(auto p: v[i]){
            int pi = p.first, node = p.second; 
            if(us[pi]) continue; 
            us[pi] = 1; 

            for(ll x = i-pi; x >= 0; x -= pi){
                for(auto u: v[x]){
                    adj[node].push_back({u.second, (i-x)/pi});
                }
                if(s[x].count(pi)) break; 
            }
        }
    }
 
    fa(i,n-1,0){
        map <int, bool> us; 

        for(auto p: v[i]){
            int pi = p.first, node = p.second; 
            if(us[pi]) continue; 
            us[pi] = 1; 

            for(ll x = i+pi; x < n; x += pi){
                for(auto u: v[x]){
                    adj[node].push_back({u.second, (x-i)/pi});
                }
                if(s[x].count(pi)) break; 
            }
        }
    }
    dij(0); 

   
    cout << ((d[1] == inf) ? -1 : d[1]) << "\n"; 
    return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 3 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3284 KB Output is correct
11 Correct 6 ms 5128 KB Output is correct
12 Correct 3 ms 3284 KB Output is correct
13 Correct 3 ms 3412 KB Output is correct
14 Correct 5 ms 4436 KB Output is correct
15 Correct 6 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3128 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 3 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3284 KB Output is correct
11 Correct 6 ms 5076 KB Output is correct
12 Correct 3 ms 3284 KB Output is correct
13 Correct 3 ms 3412 KB Output is correct
14 Correct 6 ms 4436 KB Output is correct
15 Correct 6 ms 4436 KB Output is correct
16 Correct 3 ms 3540 KB Output is correct
17 Correct 5 ms 4180 KB Output is correct
18 Correct 3 ms 3284 KB Output is correct
19 Correct 3 ms 3156 KB Output is correct
20 Correct 4 ms 3412 KB Output is correct
21 Correct 3 ms 3284 KB Output is correct
22 Correct 3 ms 3284 KB Output is correct
23 Correct 3 ms 3284 KB Output is correct
24 Correct 5 ms 3668 KB Output is correct
25 Correct 5 ms 3540 KB Output is correct
26 Correct 4 ms 3412 KB Output is correct
27 Correct 3 ms 3284 KB Output is correct
28 Correct 4 ms 3796 KB Output is correct
29 Correct 3 ms 3284 KB Output is correct
30 Correct 2 ms 3156 KB Output is correct
31 Correct 3 ms 3156 KB Output is correct
32 Correct 2 ms 3156 KB Output is correct
33 Correct 6 ms 4436 KB Output is correct
34 Correct 6 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3124 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3284 KB Output is correct
11 Correct 6 ms 5076 KB Output is correct
12 Correct 3 ms 3284 KB Output is correct
13 Correct 4 ms 3412 KB Output is correct
14 Correct 6 ms 4436 KB Output is correct
15 Correct 8 ms 4436 KB Output is correct
16 Correct 5 ms 3484 KB Output is correct
17 Correct 6 ms 4180 KB Output is correct
18 Correct 3 ms 3284 KB Output is correct
19 Correct 3 ms 3156 KB Output is correct
20 Correct 3 ms 3412 KB Output is correct
21 Correct 3 ms 3284 KB Output is correct
22 Correct 2 ms 3284 KB Output is correct
23 Correct 3 ms 3284 KB Output is correct
24 Correct 4 ms 3668 KB Output is correct
25 Correct 4 ms 3540 KB Output is correct
26 Correct 3 ms 3412 KB Output is correct
27 Correct 4 ms 3284 KB Output is correct
28 Correct 4 ms 3796 KB Output is correct
29 Correct 3 ms 3284 KB Output is correct
30 Correct 2 ms 3156 KB Output is correct
31 Correct 2 ms 3156 KB Output is correct
32 Correct 2 ms 3156 KB Output is correct
33 Correct 6 ms 4436 KB Output is correct
34 Correct 7 ms 4436 KB Output is correct
35 Correct 93 ms 39636 KB Output is correct
36 Correct 10 ms 5132 KB Output is correct
37 Correct 84 ms 43608 KB Output is correct
38 Correct 107 ms 53640 KB Output is correct
39 Correct 108 ms 54604 KB Output is correct
40 Correct 128 ms 54348 KB Output is correct
41 Correct 131 ms 54040 KB Output is correct
42 Correct 21 ms 6788 KB Output is correct
43 Correct 21 ms 6352 KB Output is correct
44 Correct 19 ms 6948 KB Output is correct
45 Correct 112 ms 59540 KB Output is correct
46 Correct 129 ms 59244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 4 ms 3288 KB Output is correct
11 Correct 6 ms 5076 KB Output is correct
12 Correct 3 ms 3284 KB Output is correct
13 Correct 3 ms 3412 KB Output is correct
14 Correct 6 ms 4436 KB Output is correct
15 Correct 5 ms 4436 KB Output is correct
16 Correct 4 ms 3540 KB Output is correct
17 Correct 5 ms 4180 KB Output is correct
18 Correct 3 ms 3284 KB Output is correct
19 Correct 2 ms 3156 KB Output is correct
20 Correct 3 ms 3412 KB Output is correct
21 Correct 3 ms 3284 KB Output is correct
22 Correct 2 ms 3280 KB Output is correct
23 Correct 3 ms 3284 KB Output is correct
24 Correct 5 ms 3668 KB Output is correct
25 Correct 5 ms 3540 KB Output is correct
26 Correct 4 ms 3412 KB Output is correct
27 Correct 3 ms 3304 KB Output is correct
28 Correct 4 ms 3796 KB Output is correct
29 Correct 3 ms 3284 KB Output is correct
30 Correct 3 ms 3156 KB Output is correct
31 Correct 3 ms 3156 KB Output is correct
32 Correct 3 ms 3156 KB Output is correct
33 Correct 5 ms 4436 KB Output is correct
34 Correct 8 ms 4436 KB Output is correct
35 Correct 105 ms 39664 KB Output is correct
36 Correct 9 ms 5204 KB Output is correct
37 Correct 85 ms 43672 KB Output is correct
38 Correct 113 ms 53636 KB Output is correct
39 Correct 119 ms 54692 KB Output is correct
40 Correct 119 ms 54392 KB Output is correct
41 Correct 142 ms 53940 KB Output is correct
42 Correct 21 ms 6824 KB Output is correct
43 Correct 24 ms 6356 KB Output is correct
44 Correct 27 ms 7024 KB Output is correct
45 Correct 110 ms 59632 KB Output is correct
46 Correct 129 ms 59268 KB Output is correct
47 Correct 103 ms 40284 KB Output is correct
48 Correct 40 ms 10180 KB Output is correct
49 Correct 31 ms 7976 KB Output is correct
50 Correct 20 ms 6484 KB Output is correct
51 Correct 72 ms 14020 KB Output is correct
52 Correct 77 ms 15048 KB Output is correct
53 Correct 57 ms 9876 KB Output is correct
54 Correct 2 ms 3028 KB Output is correct
55 Correct 3 ms 3028 KB Output is correct
56 Correct 41 ms 8368 KB Output is correct
57 Correct 13 ms 5004 KB Output is correct
58 Correct 19 ms 6800 KB Output is correct
59 Correct 21 ms 6736 KB Output is correct
60 Correct 25 ms 7252 KB Output is correct
61 Correct 25 ms 6972 KB Output is correct
62 Correct 56 ms 16516 KB Output is correct
63 Correct 75 ms 17664 KB Output is correct
64 Correct 109 ms 16976 KB Output is correct
65 Correct 118 ms 25848 KB Output is correct
66 Correct 154 ms 59196 KB Output is correct
67 Correct 161 ms 59260 KB Output is correct