Submission #245566

# Submission time Handle Problem Language Result Execution time Memory
245566 2020-07-06T18:37:12 Z mat_v Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
172 ms 65768 KB
#pragma GCC optimization ("O3")
#pragma GCC optimize("Ofast")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int n,m;
pii niz[30005];

vector<pii> graf[30005];
int dist[30005];



set<int> pos[30005];
priority_queue<pii>pq;

int main()
{

    //ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> m >> n;
    ff(i,1,n){
        cin >> niz[i].xx >> niz[i].yy;
        pos[niz[i].xx].insert(niz[i].yy);
    }

    ff(i,0,m - 1){
        for(auto c:pos[i]){

            for(int j = i + c; j < m; j += c){
                graf[i].pb({j, (j - i) / c});
                if(pos[j].count(c))break;
            }
            for(int j = i - c; j >= 0; j -= c){
                graf[i].pb({j, (i - j) / c});
                if(pos[j].count(c))break;
            }
        }
    }



    ff(i,0,m - 1)dist[i] = 1e9;
    dist[niz[1].xx] = 0;
    pq.push({0,niz[1].xx});
    while(!pq.empty()){
        pii sta = pq.top();
        pq.pop();
        sta.xx = -sta.xx;
        if(dist[sta.yy] != sta.xx)continue;
        for(auto c:graf[sta.yy]){
            if(dist[c.xx] > sta.xx + c.yy){
                dist[c.xx] = sta.xx + c.yy;
                pq.push({-dist[c.xx], c.xx});
            }
        }
    }
    if(dist[niz[2].xx] == 1e9)cout << -1 << "\n";
    else cout << dist[niz[2].xx] << "\n";
    return 0;
}

Compilation message

skyscraper.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2560 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 7 ms 2560 KB Output is correct
12 Correct 8 ms 2432 KB Output is correct
13 Correct 7 ms 2432 KB Output is correct
14 Correct 7 ms 2560 KB Output is correct
15 Correct 7 ms 2560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 8 ms 2432 KB Output is correct
3 Correct 7 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 7 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 8 ms 2560 KB Output is correct
12 Correct 7 ms 2432 KB Output is correct
13 Correct 8 ms 2432 KB Output is correct
14 Correct 7 ms 2560 KB Output is correct
15 Correct 7 ms 2560 KB Output is correct
16 Correct 7 ms 2560 KB Output is correct
17 Correct 8 ms 2688 KB Output is correct
18 Correct 7 ms 2560 KB Output is correct
19 Correct 6 ms 2560 KB Output is correct
20 Correct 9 ms 2560 KB Output is correct
21 Correct 7 ms 2560 KB Output is correct
22 Correct 7 ms 2560 KB Output is correct
23 Correct 7 ms 2560 KB Output is correct
24 Correct 8 ms 2688 KB Output is correct
25 Correct 10 ms 2688 KB Output is correct
26 Correct 7 ms 2560 KB Output is correct
27 Correct 7 ms 2560 KB Output is correct
28 Correct 8 ms 2816 KB Output is correct
29 Correct 8 ms 3200 KB Output is correct
30 Correct 7 ms 2816 KB Output is correct
31 Correct 7 ms 2944 KB Output is correct
32 Correct 7 ms 2816 KB Output is correct
33 Correct 10 ms 3840 KB Output is correct
34 Correct 10 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 8 ms 2560 KB Output is correct
12 Correct 7 ms 2432 KB Output is correct
13 Correct 7 ms 2432 KB Output is correct
14 Correct 8 ms 2560 KB Output is correct
15 Correct 7 ms 2560 KB Output is correct
16 Correct 6 ms 2560 KB Output is correct
17 Correct 8 ms 2688 KB Output is correct
18 Correct 7 ms 2560 KB Output is correct
19 Correct 7 ms 2560 KB Output is correct
20 Correct 7 ms 2560 KB Output is correct
21 Correct 7 ms 2560 KB Output is correct
22 Correct 7 ms 2560 KB Output is correct
23 Correct 7 ms 2560 KB Output is correct
24 Correct 8 ms 2688 KB Output is correct
25 Correct 8 ms 2688 KB Output is correct
26 Correct 8 ms 2688 KB Output is correct
27 Correct 7 ms 2560 KB Output is correct
28 Correct 8 ms 2816 KB Output is correct
29 Correct 8 ms 3200 KB Output is correct
30 Correct 7 ms 2816 KB Output is correct
31 Correct 7 ms 2944 KB Output is correct
32 Correct 7 ms 2816 KB Output is correct
33 Correct 11 ms 3840 KB Output is correct
34 Correct 11 ms 3840 KB Output is correct
35 Correct 38 ms 4864 KB Output is correct
36 Correct 12 ms 2944 KB Output is correct
37 Correct 35 ms 5756 KB Output is correct
38 Correct 44 ms 6136 KB Output is correct
39 Correct 43 ms 6136 KB Output is correct
40 Correct 44 ms 6136 KB Output is correct
41 Correct 42 ms 6136 KB Output is correct
42 Correct 27 ms 2940 KB Output is correct
43 Correct 30 ms 3064 KB Output is correct
44 Correct 31 ms 3192 KB Output is correct
45 Correct 42 ms 8696 KB Output is correct
46 Correct 40 ms 8696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 7 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 7 ms 2560 KB Output is correct
11 Correct 8 ms 2560 KB Output is correct
12 Correct 7 ms 2432 KB Output is correct
13 Correct 9 ms 2432 KB Output is correct
14 Correct 8 ms 2688 KB Output is correct
15 Correct 7 ms 2688 KB Output is correct
16 Correct 7 ms 2560 KB Output is correct
17 Correct 12 ms 2688 KB Output is correct
18 Correct 7 ms 2560 KB Output is correct
19 Correct 7 ms 2560 KB Output is correct
20 Correct 7 ms 2560 KB Output is correct
21 Correct 7 ms 2560 KB Output is correct
22 Correct 6 ms 2560 KB Output is correct
23 Correct 7 ms 2560 KB Output is correct
24 Correct 11 ms 2688 KB Output is correct
25 Correct 8 ms 2688 KB Output is correct
26 Correct 9 ms 2560 KB Output is correct
27 Correct 8 ms 2560 KB Output is correct
28 Correct 9 ms 2816 KB Output is correct
29 Correct 8 ms 3200 KB Output is correct
30 Correct 7 ms 2816 KB Output is correct
31 Correct 7 ms 2944 KB Output is correct
32 Correct 7 ms 2816 KB Output is correct
33 Correct 10 ms 3840 KB Output is correct
34 Correct 10 ms 3840 KB Output is correct
35 Correct 34 ms 4864 KB Output is correct
36 Correct 10 ms 2944 KB Output is correct
37 Correct 32 ms 5760 KB Output is correct
38 Correct 42 ms 6136 KB Output is correct
39 Correct 42 ms 6136 KB Output is correct
40 Correct 43 ms 6136 KB Output is correct
41 Correct 42 ms 6136 KB Output is correct
42 Correct 24 ms 3072 KB Output is correct
43 Correct 24 ms 2944 KB Output is correct
44 Correct 25 ms 3072 KB Output is correct
45 Correct 40 ms 8604 KB Output is correct
46 Correct 42 ms 8704 KB Output is correct
47 Correct 68 ms 13172 KB Output is correct
48 Correct 35 ms 6388 KB Output is correct
49 Correct 33 ms 5496 KB Output is correct
50 Correct 25 ms 4992 KB Output is correct
51 Correct 65 ms 8452 KB Output is correct
52 Correct 67 ms 8892 KB Output is correct
53 Correct 42 ms 6132 KB Output is correct
54 Correct 8 ms 3072 KB Output is correct
55 Correct 9 ms 3452 KB Output is correct
56 Correct 31 ms 5368 KB Output is correct
57 Correct 41 ms 11652 KB Output is correct
58 Correct 22 ms 3960 KB Output is correct
59 Correct 31 ms 4468 KB Output is correct
60 Correct 29 ms 4996 KB Output is correct
61 Correct 30 ms 4480 KB Output is correct
62 Correct 45 ms 9600 KB Output is correct
63 Correct 79 ms 25840 KB Output is correct
64 Correct 89 ms 28784 KB Output is correct
65 Correct 109 ms 38772 KB Output is correct
66 Correct 165 ms 65764 KB Output is correct
67 Correct 172 ms 65768 KB Output is correct