Submission #908048

# Submission time Handle Problem Language Result Execution time Memory
908048 2024-01-16T07:29:36 Z treap_enjoyer Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
545 ms 4080 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast,unroll-loops")

#define ll long long
#define all(x) x.begin(), x.end()
#define ld long double
#define pii pair<int, int>

using namespace std;
using namespace __gnu_pbds;

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream cin("input.txt");
    // ofstream cout("output.txt");
    int n, m;
    cin >> n >> m;
    vector<int> b(m);
    vector<int> p(m);
    vector<int> d(n, INF);
    vector<vector<int> > g(n); 
    for(int i = 0; i < m; i++){
        cin >> b[i] >> p[i];
        g[b[i]].push_back(p[i]);
    }
    d[b[0]] = 0;
    set<pair<int, int> > s;
    s.insert({0, b[0]});
    while(!s.empty()){
        int cv = s.begin() -> second;
        int cd = s.begin() -> first;
        s.erase(s.begin());
        for(auto i: g[cv]){
            int cx = cv;
            int cy = 0;
            while(cx >= 0){
                if(cd + cy < d[cx]){
                    s.erase({d[cx], cx});
                    d[cx] = cd + cy;
                    s.insert({d[cx], cx});
                }
                cx -= i;
                cy++;
            }
            cx = cv;
            cy = 0;
            while(cx < n){
                if(cd + cy < d[cx]){
                    s.erase({d[cx], cx});
                    d[cx] = cd + cy;
                    s.insert({d[cx], cx});
                }
                cx += i;
                cy++;
            }
        }
    }
    if(d[b[1]] == INF){
        cout << "-1" << endl;
    }
    else{
        cout << d[b[1]] << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 548 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 2 ms 600 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 4 ms 604 KB Output is correct
34 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 4 ms 464 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 456 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 3 ms 600 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 5 ms 1120 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 5 ms 860 KB Output is correct
38 Correct 8 ms 1112 KB Output is correct
39 Correct 6 ms 1116 KB Output is correct
40 Correct 7 ms 1112 KB Output is correct
41 Correct 6 ms 1116 KB Output is correct
42 Correct 38 ms 1116 KB Output is correct
43 Correct 38 ms 1116 KB Output is correct
44 Correct 39 ms 1196 KB Output is correct
45 Correct 6 ms 1112 KB Output is correct
46 Correct 6 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 388 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 4 ms 604 KB Output is correct
34 Correct 4 ms 604 KB Output is correct
35 Correct 6 ms 1116 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 5 ms 956 KB Output is correct
38 Correct 8 ms 1116 KB Output is correct
39 Correct 6 ms 1116 KB Output is correct
40 Correct 7 ms 1116 KB Output is correct
41 Correct 6 ms 1116 KB Output is correct
42 Correct 39 ms 1112 KB Output is correct
43 Correct 39 ms 1112 KB Output is correct
44 Correct 39 ms 1196 KB Output is correct
45 Correct 7 ms 1112 KB Output is correct
46 Correct 8 ms 1140 KB Output is correct
47 Correct 20 ms 2156 KB Output is correct
48 Correct 5 ms 1736 KB Output is correct
49 Correct 5 ms 1896 KB Output is correct
50 Correct 4 ms 1628 KB Output is correct
51 Correct 40 ms 3676 KB Output is correct
52 Correct 34 ms 3420 KB Output is correct
53 Correct 14 ms 3676 KB Output is correct
54 Correct 4 ms 1884 KB Output is correct
55 Correct 4 ms 1884 KB Output is correct
56 Correct 545 ms 4080 KB Output is correct
57 Correct 70 ms 2720 KB Output is correct
58 Correct 539 ms 2644 KB Output is correct
59 Correct 526 ms 2556 KB Output is correct
60 Correct 523 ms 2548 KB Output is correct
61 Correct 473 ms 2592 KB Output is correct
62 Correct 9 ms 2652 KB Output is correct
63 Correct 48 ms 3304 KB Output is correct
64 Correct 49 ms 3164 KB Output is correct
65 Correct 59 ms 3160 KB Output is correct
66 Correct 88 ms 3356 KB Output is correct
67 Correct 81 ms 3164 KB Output is correct