답안 #36801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36801 2017-12-14T18:56:33 Z imaxblue Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
319 ms 20944 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define p_q priority_queue
#define MN 1000000009

int n, m, P, D, X, K, t, p[30005], j[30005], d[30005][105], J;
p_q<pair<int, pii> > pq;
bool u[30005][105];
vector<int> v[30005];
int main(){
    memset(d, 0x3f3f3f3f, sizeof d);
    scanf("%i%i", &n, &m);
    for (int l=0; l<m; ++l){
        scanf("%i%i", &p[l], &j[l]);
        v[p[l]].pb(j[l]);
    }
    X=p[1];
    pq.push(mp(0, mp(p[0], 0))); d[p[0]][0]=0;
    while(!pq.empty()){
        P=pq.top().y.x; K=pq.top().y.y; pq.pop();
        if (u[P][K]) continue;
        u[P][K]=1;
        if (d[P][K]<d[P][0]){
            d[P][0]=d[P][K];
            pq.push(mp(-d[P][K], mp(P, 0)));
        }
        //cout << P << ' ' << d[P] << endl;
        if (P==X){
            cout << d[P][K]; return 0;
        }
        if (K>0){
            if (P-K>=0){
                if (d[P][K]+1<d[P-K][K]){
                    d[P-K][K]=d[P][K]+1; pq.push(mp(-d[P][K]-1, mp(P-K, K)));
                }
            }
            if (P+K<=n){
                if (d[P][K]+1<d[P+K][K]){
                    d[P+K][K]=d[P][K]+1; pq.push(mp(-d[P][K]-1, mp(P+K, K)));
                }
            }
            continue;
        }
        for (int l2=0; l2<v[P].size(); ++l2){
            if (l2>0 && v[P][l2]==v[P][l2-1]) continue;
            J=v[P][l2];
            if (J<50){
                if (P-J>=0){
                    if (d[P][K]+1<d[P-J][J]){
                        d[P-J][J]=d[P][K]+1; pq.push(mp(-d[P][K]-1, mp(P-J, J)));
                    }
                }
                if (P+J<n){
                    if (d[P][K]+1<d[P+J][J]){
                        d[P+J][J]=d[P][K]+1; pq.push(mp(-d[P][K]-1, mp(P+J, J)));
                    }
                }
            }
            else
            for (int l=P%J; l<n; l+=J){
                t=max((l-P)/J, -(l-P)/J)+d[P][K];
                if (t<d[l][0]){
                    d[l][0]=t; pq.push(mp(-t, mp(l, 0)));
                }
            }
        }
        /*for (int l=0; l<m; ++l){
            if ((p[l]-p[P])%j[P]) continue;
            t=max((p[l]-p[P])/j[P], -(p[l]-p[P])/j[P])+d[P];
            if (t<d[l]){
                d[l]=t; pq.push(mp(-t, l));
            }
        }*/
    }
    cout << -1;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:57:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int l2=0; l2<v[P].size(); ++l2){
                          ^
skyscraper.cpp:25:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i", &n, &m);
                          ^
skyscraper.cpp:27:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i", &p[l], &j[l]);
                                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 18336 KB Output is correct
2 Correct 0 ms 18336 KB Output is correct
3 Correct 3 ms 18336 KB Output is correct
4 Correct 3 ms 18336 KB Output is correct
5 Correct 0 ms 18336 KB Output is correct
6 Correct 0 ms 18336 KB Output is correct
7 Correct 3 ms 18336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18336 KB Output is correct
2 Correct 3 ms 18336 KB Output is correct
3 Correct 0 ms 18336 KB Output is correct
4 Correct 0 ms 18336 KB Output is correct
5 Correct 0 ms 18336 KB Output is correct
6 Correct 6 ms 18336 KB Output is correct
7 Correct 0 ms 18336 KB Output is correct
8 Correct 3 ms 18336 KB Output is correct
9 Correct 6 ms 18336 KB Output is correct
10 Correct 9 ms 18336 KB Output is correct
11 Correct 0 ms 18336 KB Output is correct
12 Correct 3 ms 18336 KB Output is correct
13 Correct 3 ms 18336 KB Output is correct
14 Correct 0 ms 18476 KB Output is correct
15 Correct 0 ms 18476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18336 KB Output is correct
2 Correct 3 ms 18336 KB Output is correct
3 Correct 0 ms 18336 KB Output is correct
4 Correct 0 ms 18336 KB Output is correct
5 Correct 0 ms 18336 KB Output is correct
6 Correct 3 ms 18336 KB Output is correct
7 Correct 3 ms 18336 KB Output is correct
8 Correct 3 ms 18336 KB Output is correct
9 Correct 0 ms 18336 KB Output is correct
10 Correct 3 ms 18336 KB Output is correct
11 Correct 0 ms 18336 KB Output is correct
12 Correct 0 ms 18336 KB Output is correct
13 Correct 3 ms 18336 KB Output is correct
14 Correct 0 ms 18476 KB Output is correct
15 Correct 3 ms 18476 KB Output is correct
16 Correct 0 ms 18336 KB Output is correct
17 Correct 0 ms 18336 KB Output is correct
18 Correct 3 ms 18336 KB Output is correct
19 Correct 3 ms 18336 KB Output is correct
20 Correct 3 ms 18468 KB Output is correct
21 Correct 6 ms 18336 KB Output is correct
22 Correct 3 ms 18336 KB Output is correct
23 Correct 6 ms 18336 KB Output is correct
24 Correct 3 ms 18472 KB Output is correct
25 Correct 0 ms 18336 KB Output is correct
26 Correct 3 ms 18336 KB Output is correct
27 Correct 0 ms 18336 KB Output is correct
28 Correct 3 ms 18468 KB Output is correct
29 Correct 9 ms 18468 KB Output is correct
30 Correct 6 ms 18336 KB Output is correct
31 Correct 3 ms 18336 KB Output is correct
32 Correct 6 ms 18336 KB Output is correct
33 Correct 19 ms 18620 KB Output is correct
34 Correct 6 ms 18620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 18336 KB Output is correct
2 Correct 0 ms 18336 KB Output is correct
3 Correct 3 ms 18336 KB Output is correct
4 Correct 0 ms 18336 KB Output is correct
5 Correct 3 ms 18336 KB Output is correct
6 Correct 3 ms 18336 KB Output is correct
7 Correct 0 ms 18336 KB Output is correct
8 Correct 0 ms 18336 KB Output is correct
9 Correct 0 ms 18336 KB Output is correct
10 Correct 3 ms 18336 KB Output is correct
11 Correct 0 ms 18336 KB Output is correct
12 Correct 3 ms 18336 KB Output is correct
13 Correct 0 ms 18336 KB Output is correct
14 Correct 3 ms 18476 KB Output is correct
15 Correct 0 ms 18476 KB Output is correct
16 Correct 0 ms 18336 KB Output is correct
17 Correct 0 ms 18336 KB Output is correct
18 Correct 3 ms 18336 KB Output is correct
19 Correct 0 ms 18336 KB Output is correct
20 Correct 0 ms 18468 KB Output is correct
21 Correct 3 ms 18336 KB Output is correct
22 Correct 0 ms 18336 KB Output is correct
23 Correct 3 ms 18336 KB Output is correct
24 Correct 3 ms 18472 KB Output is correct
25 Correct 3 ms 18336 KB Output is correct
26 Correct 3 ms 18336 KB Output is correct
27 Correct 3 ms 18336 KB Output is correct
28 Correct 6 ms 18468 KB Output is correct
29 Correct 9 ms 18468 KB Output is correct
30 Correct 6 ms 18336 KB Output is correct
31 Correct 9 ms 18336 KB Output is correct
32 Correct 9 ms 18336 KB Output is correct
33 Correct 19 ms 18620 KB Output is correct
34 Correct 13 ms 18620 KB Output is correct
35 Correct 9 ms 18600 KB Output is correct
36 Correct 6 ms 18468 KB Output is correct
37 Correct 9 ms 18600 KB Output is correct
38 Correct 9 ms 18752 KB Output is correct
39 Correct 9 ms 18600 KB Output is correct
40 Correct 6 ms 18752 KB Output is correct
41 Correct 9 ms 18752 KB Output is correct
42 Correct 9 ms 18612 KB Output is correct
43 Correct 6 ms 18612 KB Output is correct
44 Correct 13 ms 18608 KB Output is correct
45 Correct 26 ms 18780 KB Output is correct
46 Correct 13 ms 18784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18336 KB Output is correct
2 Correct 0 ms 18336 KB Output is correct
3 Correct 0 ms 18336 KB Output is correct
4 Correct 0 ms 18336 KB Output is correct
5 Correct 0 ms 18336 KB Output is correct
6 Correct 0 ms 18336 KB Output is correct
7 Correct 0 ms 18336 KB Output is correct
8 Correct 0 ms 18336 KB Output is correct
9 Correct 0 ms 18336 KB Output is correct
10 Correct 0 ms 18336 KB Output is correct
11 Correct 0 ms 18336 KB Output is correct
12 Correct 3 ms 18336 KB Output is correct
13 Correct 0 ms 18336 KB Output is correct
14 Correct 3 ms 18476 KB Output is correct
15 Correct 0 ms 18476 KB Output is correct
16 Correct 0 ms 18336 KB Output is correct
17 Correct 3 ms 18336 KB Output is correct
18 Correct 0 ms 18336 KB Output is correct
19 Correct 0 ms 18336 KB Output is correct
20 Correct 0 ms 18468 KB Output is correct
21 Correct 0 ms 18336 KB Output is correct
22 Correct 0 ms 18336 KB Output is correct
23 Correct 0 ms 18336 KB Output is correct
24 Correct 0 ms 18472 KB Output is correct
25 Correct 3 ms 18336 KB Output is correct
26 Correct 0 ms 18336 KB Output is correct
27 Correct 3 ms 18336 KB Output is correct
28 Correct 3 ms 18468 KB Output is correct
29 Correct 9 ms 18468 KB Output is correct
30 Correct 6 ms 18336 KB Output is correct
31 Correct 6 ms 18336 KB Output is correct
32 Correct 6 ms 18336 KB Output is correct
33 Correct 13 ms 18620 KB Output is correct
34 Correct 9 ms 18620 KB Output is correct
35 Correct 3 ms 18600 KB Output is correct
36 Correct 3 ms 18468 KB Output is correct
37 Correct 6 ms 18600 KB Output is correct
38 Correct 16 ms 18752 KB Output is correct
39 Correct 13 ms 18600 KB Output is correct
40 Correct 9 ms 18752 KB Output is correct
41 Correct 13 ms 18752 KB Output is correct
42 Correct 6 ms 18612 KB Output is correct
43 Correct 0 ms 18612 KB Output is correct
44 Correct 16 ms 18608 KB Output is correct
45 Correct 29 ms 18780 KB Output is correct
46 Correct 9 ms 18784 KB Output is correct
47 Correct 9 ms 19340 KB Output is correct
48 Correct 6 ms 18864 KB Output is correct
49 Correct 9 ms 18864 KB Output is correct
50 Correct 9 ms 18732 KB Output is correct
51 Correct 43 ms 19588 KB Output is correct
52 Correct 26 ms 19592 KB Output is correct
53 Correct 16 ms 18996 KB Output is correct
54 Correct 6 ms 18336 KB Output is correct
55 Correct 9 ms 18336 KB Output is correct
56 Correct 19 ms 19260 KB Output is correct
57 Correct 0 ms 18468 KB Output is correct
58 Correct 16 ms 18608 KB Output is correct
59 Correct 16 ms 18608 KB Output is correct
60 Correct 23 ms 18616 KB Output is correct
61 Correct 19 ms 18624 KB Output is correct
62 Correct 46 ms 19260 KB Output is correct
63 Correct 63 ms 19804 KB Output is correct
64 Correct 66 ms 19768 KB Output is correct
65 Correct 109 ms 20944 KB Output is correct
66 Correct 319 ms 20900 KB Output is correct
67 Correct 146 ms 20900 KB Output is correct