Submission #315868

# Submission time Handle Problem Language Result Execution time Memory
315868 2020-10-24T07:51:46 Z soroush Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
978 ms 62196 KB
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 30100;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , m;
int b[maxn] , p[maxn];
int dist[500][maxn];

struct tr{
    int d , p , pos;
    tr(int a , int b , int x):
        d(a) , p(b) , pos(x){}
    friend bool operator < (tr a , tr b){
        return(a.d > b.d);
    }
};

vector < int > vec[maxn];
priority_queue < tr > q;

void add(int d , int p , int pos){
    int cur = d;
    int x = pos;
    while(x - p > -1){
        x-=p;
        cur++;
        if(dist[0][x] > cur){
            dist[0][x] = cur;
            q.push({cur , 0 , x});
        }
    }
    cur = d;
    x = pos;
    while(x + p < n){
        x += p;
        cur++;
        if(dist[0][x] > cur){
            dist[0][x] = cur;
            q.push({cur , 0 , x});
        }
    }
}

void djk(){
    ms(dist , 63);
    dist[0][b[0]] = 0;
    q.push({ 0 , 0 , b[0]});
    while(!q.empty()){
        auto v = q.top();
        q.pop();
        if(v.p == 0){ //jasoosi
            for(auto x : vec[v.pos]){
                if(p[x] < 300 and dist[p[x]][v.pos] > v.d )
                        dist[p[x]][v.pos] = v.d,
                        q.push({v.d , p[x] , v.pos});
                else{
                    add(v.d , p[x] , v.pos);
                }
            }
        }
        else{
            if(dist[0][v.pos] > v.d){
                dist[0][v.pos] = v.d;
                q.push({v.d , 0 , v.pos});
            }
            if(v.pos + v.p < n and dist[v.p][v.pos + v.p] > v.d + 1){
                dist[v.p][v.pos + v.p] = v.d + 1;
                q.push({v.d + 1 , v.p , v.pos + v.p});
            }
            if(v.pos - v.p > -1 and dist[v.p][v.pos - v.p] > v.d + 1){
                dist[v.p][v.pos - v.p] = v.d + 1;
                q.push({v.d + 1 , v.p , v.pos - v.p});
            }
        }
    }
    if(dist[0][b[1]] == dist[400][2])
        dokme(-1);
    dokme(dist[0][b[1]]);
}

int32_t main(){
    migmig;
    cin >> n >> m;
    for(int i = 0 ; i < m ; i ++)
        cin >> b[i] >> p[i];
    for(int i = 0 ; i < m ; i ++)
        vec[b[i]].pb(i);
    djk();
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 59896 KB Output is correct
2 Correct 34 ms 59904 KB Output is correct
3 Correct 33 ms 59896 KB Output is correct
4 Correct 32 ms 59896 KB Output is correct
5 Correct 33 ms 59896 KB Output is correct
6 Correct 34 ms 59896 KB Output is correct
7 Correct 33 ms 59904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 59896 KB Output is correct
2 Correct 34 ms 59900 KB Output is correct
3 Correct 36 ms 59896 KB Output is correct
4 Correct 34 ms 59896 KB Output is correct
5 Correct 35 ms 60024 KB Output is correct
6 Correct 34 ms 59904 KB Output is correct
7 Correct 35 ms 59896 KB Output is correct
8 Correct 34 ms 59900 KB Output is correct
9 Correct 36 ms 59904 KB Output is correct
10 Correct 35 ms 60032 KB Output is correct
11 Correct 36 ms 60024 KB Output is correct
12 Correct 35 ms 59932 KB Output is correct
13 Correct 37 ms 60024 KB Output is correct
14 Correct 36 ms 60052 KB Output is correct
15 Correct 36 ms 60024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 60024 KB Output is correct
2 Correct 35 ms 59896 KB Output is correct
3 Correct 35 ms 59896 KB Output is correct
4 Correct 36 ms 59896 KB Output is correct
5 Correct 35 ms 59896 KB Output is correct
6 Correct 37 ms 59896 KB Output is correct
7 Correct 35 ms 59904 KB Output is correct
8 Correct 35 ms 59896 KB Output is correct
9 Correct 36 ms 59896 KB Output is correct
10 Correct 36 ms 60024 KB Output is correct
11 Correct 36 ms 60024 KB Output is correct
12 Correct 36 ms 60024 KB Output is correct
13 Correct 35 ms 60024 KB Output is correct
14 Correct 36 ms 60024 KB Output is correct
15 Correct 35 ms 60024 KB Output is correct
16 Correct 35 ms 60024 KB Output is correct
17 Correct 37 ms 60024 KB Output is correct
18 Correct 35 ms 60024 KB Output is correct
19 Correct 35 ms 60024 KB Output is correct
20 Correct 40 ms 60152 KB Output is correct
21 Correct 36 ms 60024 KB Output is correct
22 Correct 35 ms 60024 KB Output is correct
23 Correct 36 ms 60160 KB Output is correct
24 Correct 36 ms 60024 KB Output is correct
25 Correct 36 ms 60024 KB Output is correct
26 Correct 40 ms 60024 KB Output is correct
27 Correct 39 ms 60024 KB Output is correct
28 Correct 36 ms 60024 KB Output is correct
29 Correct 40 ms 60024 KB Output is correct
30 Correct 37 ms 59896 KB Output is correct
31 Correct 37 ms 60024 KB Output is correct
32 Correct 37 ms 60028 KB Output is correct
33 Correct 44 ms 60024 KB Output is correct
34 Correct 46 ms 60024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 59900 KB Output is correct
2 Correct 35 ms 59904 KB Output is correct
3 Correct 35 ms 59896 KB Output is correct
4 Correct 35 ms 59896 KB Output is correct
5 Correct 35 ms 59896 KB Output is correct
6 Correct 35 ms 59896 KB Output is correct
7 Correct 35 ms 59904 KB Output is correct
8 Correct 37 ms 59896 KB Output is correct
9 Correct 35 ms 60024 KB Output is correct
10 Correct 36 ms 60024 KB Output is correct
11 Correct 37 ms 60032 KB Output is correct
12 Correct 36 ms 60024 KB Output is correct
13 Correct 36 ms 60032 KB Output is correct
14 Correct 37 ms 60152 KB Output is correct
15 Correct 37 ms 60024 KB Output is correct
16 Correct 35 ms 60056 KB Output is correct
17 Correct 37 ms 60024 KB Output is correct
18 Correct 35 ms 60032 KB Output is correct
19 Correct 35 ms 60032 KB Output is correct
20 Correct 40 ms 60152 KB Output is correct
21 Correct 36 ms 60032 KB Output is correct
22 Correct 36 ms 60024 KB Output is correct
23 Correct 36 ms 60024 KB Output is correct
24 Correct 38 ms 60024 KB Output is correct
25 Correct 36 ms 60024 KB Output is correct
26 Correct 40 ms 60024 KB Output is correct
27 Correct 39 ms 60032 KB Output is correct
28 Correct 37 ms 60024 KB Output is correct
29 Correct 39 ms 60024 KB Output is correct
30 Correct 37 ms 59896 KB Output is correct
31 Correct 37 ms 60024 KB Output is correct
32 Correct 37 ms 60024 KB Output is correct
33 Correct 46 ms 60024 KB Output is correct
34 Correct 44 ms 60024 KB Output is correct
35 Correct 48 ms 60664 KB Output is correct
36 Correct 38 ms 60160 KB Output is correct
37 Correct 55 ms 60852 KB Output is correct
38 Correct 55 ms 60792 KB Output is correct
39 Correct 54 ms 60664 KB Output is correct
40 Correct 55 ms 60772 KB Output is correct
41 Correct 54 ms 60876 KB Output is correct
42 Correct 104 ms 60536 KB Output is correct
43 Correct 99 ms 60664 KB Output is correct
44 Correct 104 ms 60536 KB Output is correct
45 Correct 88 ms 60992 KB Output is correct
46 Correct 88 ms 60984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 59896 KB Output is correct
2 Correct 36 ms 59904 KB Output is correct
3 Correct 35 ms 59896 KB Output is correct
4 Correct 34 ms 59904 KB Output is correct
5 Correct 36 ms 59896 KB Output is correct
6 Correct 36 ms 59896 KB Output is correct
7 Correct 36 ms 59896 KB Output is correct
8 Correct 38 ms 59904 KB Output is correct
9 Correct 35 ms 59896 KB Output is correct
10 Correct 36 ms 60024 KB Output is correct
11 Correct 36 ms 60024 KB Output is correct
12 Correct 36 ms 60024 KB Output is correct
13 Correct 35 ms 60024 KB Output is correct
14 Correct 36 ms 60032 KB Output is correct
15 Correct 36 ms 60028 KB Output is correct
16 Correct 35 ms 59948 KB Output is correct
17 Correct 38 ms 60024 KB Output is correct
18 Correct 41 ms 60024 KB Output is correct
19 Correct 35 ms 59984 KB Output is correct
20 Correct 39 ms 60032 KB Output is correct
21 Correct 35 ms 60024 KB Output is correct
22 Correct 35 ms 60032 KB Output is correct
23 Correct 43 ms 60024 KB Output is correct
24 Correct 38 ms 60152 KB Output is correct
25 Correct 35 ms 60024 KB Output is correct
26 Correct 40 ms 60024 KB Output is correct
27 Correct 40 ms 60160 KB Output is correct
28 Correct 37 ms 60024 KB Output is correct
29 Correct 39 ms 60024 KB Output is correct
30 Correct 37 ms 60024 KB Output is correct
31 Correct 38 ms 60024 KB Output is correct
32 Correct 37 ms 60024 KB Output is correct
33 Correct 44 ms 60068 KB Output is correct
34 Correct 44 ms 60032 KB Output is correct
35 Correct 48 ms 60640 KB Output is correct
36 Correct 38 ms 60152 KB Output is correct
37 Correct 55 ms 60728 KB Output is correct
38 Correct 53 ms 60796 KB Output is correct
39 Correct 56 ms 60664 KB Output is correct
40 Correct 55 ms 60664 KB Output is correct
41 Correct 54 ms 60664 KB Output is correct
42 Correct 103 ms 60544 KB Output is correct
43 Correct 97 ms 60536 KB Output is correct
44 Correct 103 ms 60536 KB Output is correct
45 Correct 87 ms 61048 KB Output is correct
46 Correct 87 ms 60984 KB Output is correct
47 Correct 110 ms 61112 KB Output is correct
48 Correct 43 ms 60672 KB Output is correct
49 Correct 40 ms 60696 KB Output is correct
50 Correct 40 ms 60536 KB Output is correct
51 Correct 73 ms 61368 KB Output is correct
52 Correct 75 ms 61372 KB Output is correct
53 Correct 45 ms 60924 KB Output is correct
54 Correct 34 ms 59896 KB Output is correct
55 Correct 36 ms 59904 KB Output is correct
56 Correct 794 ms 61752 KB Output is correct
57 Correct 163 ms 61812 KB Output is correct
58 Correct 585 ms 60792 KB Output is correct
59 Correct 978 ms 60664 KB Output is correct
60 Correct 681 ms 60536 KB Output is correct
61 Correct 827 ms 60536 KB Output is correct
62 Correct 53 ms 61180 KB Output is correct
63 Correct 117 ms 62192 KB Output is correct
64 Correct 183 ms 62192 KB Output is correct
65 Correct 450 ms 62196 KB Output is correct
66 Correct 735 ms 60992 KB Output is correct
67 Correct 743 ms 60984 KB Output is correct