Submission #205422

# Submission time Handle Problem Language Result Execution time Memory
205422 2020-02-28T22:45:01 Z anonymous Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
92 ms 5612 KB
#include<iostream>
#include<set>
#include<queue>
#include<utility>
#define MAXN 30005
using namespace std;
int N, M, S, T, bi, pi, dist[MAXN];
bool vis[MAXN];
set <int> D[MAXN];
priority_queue<pair<int,int> > PQ;

int main() {
    //freopen("jarin.txt","r",stdin);
    scanf("%d %d",&N,&M);
    for (int i=0; i<M; i++) {
        scanf("%d %d",&bi,&pi);
        D[bi].insert(pi);
        if (i == 0) {S = bi;}
        else if (i == 1) {T = bi;}
    }
    for (int i=0; i<N; i++) {
        dist[i] = 1<<30;
    }
    dist[S] = 0;
    PQ.push({0, S});
    while (PQ.size()) {
        int cur = PQ.top().second;
        PQ.pop();
        if (vis[cur]) {continue;}
        if (cur == T) {
            printf("%d", dist[cur]);
            return(0);
        }
        vis[cur]=true;
        for (auto p: D[cur]) {
            for (int i=1; i<=N; i++) {
                if (cur + i*p >= N) {break;}
                if (dist[cur + i*p] > dist[cur] + i) {
                    dist[cur + i*p] = dist[cur] + i;
                    PQ.push({-dist[cur + i*p], cur + i*p});
                }
                if (D[cur + i*p].find(p) != D[cur + i*p].end()) {break;}
            }
            for (int i=-1; i>=-N; i--) {
                if (cur + i*p < 0) {break;}
                if (dist[cur + i*p] > dist[cur] - i) {
                    dist[cur + i*p] = dist[cur] - i;
                    PQ.push({-dist[cur + i*p], cur + i*p});
                }
                if (D[cur + i*p].find(p) != D[cur + i*p].end()) {break;}
            }
        }
    }
    printf("-1");
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&bi,&pi);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1784 KB Output is correct
2 Correct 6 ms 1784 KB Output is correct
3 Correct 6 ms 1660 KB Output is correct
4 Correct 6 ms 1784 KB Output is correct
5 Correct 6 ms 1784 KB Output is correct
6 Correct 6 ms 1656 KB Output is correct
7 Correct 6 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1784 KB Output is correct
2 Correct 6 ms 1656 KB Output is correct
3 Correct 6 ms 1660 KB Output is correct
4 Correct 6 ms 1656 KB Output is correct
5 Correct 6 ms 1656 KB Output is correct
6 Correct 6 ms 1784 KB Output is correct
7 Correct 6 ms 1656 KB Output is correct
8 Correct 6 ms 1784 KB Output is correct
9 Correct 5 ms 1784 KB Output is correct
10 Correct 6 ms 1784 KB Output is correct
11 Correct 7 ms 1784 KB Output is correct
12 Correct 6 ms 1784 KB Output is correct
13 Correct 6 ms 1784 KB Output is correct
14 Correct 6 ms 1912 KB Output is correct
15 Correct 6 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1784 KB Output is correct
2 Correct 5 ms 1784 KB Output is correct
3 Correct 7 ms 1784 KB Output is correct
4 Correct 6 ms 1708 KB Output is correct
5 Correct 5 ms 1784 KB Output is correct
6 Correct 5 ms 1784 KB Output is correct
7 Correct 6 ms 1784 KB Output is correct
8 Correct 6 ms 1784 KB Output is correct
9 Correct 5 ms 1784 KB Output is correct
10 Correct 6 ms 1784 KB Output is correct
11 Correct 6 ms 1784 KB Output is correct
12 Correct 6 ms 1784 KB Output is correct
13 Correct 6 ms 1784 KB Output is correct
14 Correct 6 ms 1784 KB Output is correct
15 Correct 6 ms 1784 KB Output is correct
16 Correct 7 ms 1784 KB Output is correct
17 Correct 7 ms 1784 KB Output is correct
18 Correct 6 ms 1784 KB Output is correct
19 Correct 6 ms 1784 KB Output is correct
20 Correct 7 ms 2040 KB Output is correct
21 Correct 7 ms 1784 KB Output is correct
22 Correct 6 ms 1784 KB Output is correct
23 Correct 7 ms 1784 KB Output is correct
24 Correct 7 ms 1912 KB Output is correct
25 Correct 6 ms 1784 KB Output is correct
26 Correct 6 ms 1784 KB Output is correct
27 Correct 7 ms 1784 KB Output is correct
28 Correct 7 ms 1912 KB Output is correct
29 Correct 7 ms 1912 KB Output is correct
30 Correct 6 ms 1784 KB Output is correct
31 Correct 7 ms 1912 KB Output is correct
32 Correct 6 ms 1784 KB Output is correct
33 Correct 9 ms 2044 KB Output is correct
34 Correct 8 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1784 KB Output is correct
2 Correct 5 ms 1784 KB Output is correct
3 Correct 6 ms 1784 KB Output is correct
4 Correct 6 ms 1656 KB Output is correct
5 Correct 6 ms 1656 KB Output is correct
6 Correct 6 ms 1656 KB Output is correct
7 Correct 6 ms 1784 KB Output is correct
8 Correct 6 ms 1784 KB Output is correct
9 Correct 6 ms 1784 KB Output is correct
10 Correct 6 ms 1784 KB Output is correct
11 Correct 7 ms 1784 KB Output is correct
12 Correct 6 ms 1784 KB Output is correct
13 Correct 6 ms 1784 KB Output is correct
14 Correct 7 ms 1784 KB Output is correct
15 Correct 7 ms 1784 KB Output is correct
16 Correct 6 ms 1784 KB Output is correct
17 Correct 7 ms 1784 KB Output is correct
18 Correct 6 ms 1784 KB Output is correct
19 Correct 6 ms 1788 KB Output is correct
20 Correct 7 ms 1784 KB Output is correct
21 Correct 6 ms 1784 KB Output is correct
22 Correct 6 ms 1784 KB Output is correct
23 Correct 6 ms 1784 KB Output is correct
24 Correct 7 ms 1912 KB Output is correct
25 Correct 7 ms 1912 KB Output is correct
26 Correct 7 ms 1912 KB Output is correct
27 Correct 6 ms 1784 KB Output is correct
28 Correct 6 ms 1784 KB Output is correct
29 Correct 7 ms 1912 KB Output is correct
30 Correct 6 ms 1784 KB Output is correct
31 Correct 6 ms 1912 KB Output is correct
32 Correct 7 ms 1912 KB Output is correct
33 Correct 8 ms 2040 KB Output is correct
34 Correct 8 ms 2168 KB Output is correct
35 Correct 21 ms 3192 KB Output is correct
36 Correct 7 ms 2040 KB Output is correct
37 Correct 17 ms 2936 KB Output is correct
38 Correct 25 ms 3480 KB Output is correct
39 Correct 20 ms 3448 KB Output is correct
40 Correct 20 ms 3448 KB Output is correct
41 Correct 27 ms 3448 KB Output is correct
42 Correct 12 ms 2040 KB Output is correct
43 Correct 12 ms 1912 KB Output is correct
44 Correct 12 ms 2040 KB Output is correct
45 Correct 25 ms 3576 KB Output is correct
46 Correct 25 ms 3576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1784 KB Output is correct
2 Correct 6 ms 1784 KB Output is correct
3 Correct 6 ms 1656 KB Output is correct
4 Correct 6 ms 1784 KB Output is correct
5 Correct 5 ms 1784 KB Output is correct
6 Correct 6 ms 1784 KB Output is correct
7 Correct 6 ms 1784 KB Output is correct
8 Correct 6 ms 1784 KB Output is correct
9 Correct 6 ms 1784 KB Output is correct
10 Correct 6 ms 1784 KB Output is correct
11 Correct 6 ms 1784 KB Output is correct
12 Correct 6 ms 1784 KB Output is correct
13 Correct 7 ms 1784 KB Output is correct
14 Correct 7 ms 1784 KB Output is correct
15 Correct 7 ms 1784 KB Output is correct
16 Correct 6 ms 1784 KB Output is correct
17 Correct 7 ms 1788 KB Output is correct
18 Correct 6 ms 1784 KB Output is correct
19 Correct 6 ms 1784 KB Output is correct
20 Correct 6 ms 1784 KB Output is correct
21 Correct 6 ms 1784 KB Output is correct
22 Correct 6 ms 1784 KB Output is correct
23 Correct 6 ms 1784 KB Output is correct
24 Correct 7 ms 1912 KB Output is correct
25 Correct 6 ms 1912 KB Output is correct
26 Correct 6 ms 1784 KB Output is correct
27 Correct 6 ms 1784 KB Output is correct
28 Correct 6 ms 1784 KB Output is correct
29 Correct 7 ms 1912 KB Output is correct
30 Correct 6 ms 1912 KB Output is correct
31 Correct 7 ms 1912 KB Output is correct
32 Correct 6 ms 1912 KB Output is correct
33 Correct 8 ms 2040 KB Output is correct
34 Correct 8 ms 2040 KB Output is correct
35 Correct 21 ms 3192 KB Output is correct
36 Correct 7 ms 2040 KB Output is correct
37 Correct 17 ms 2936 KB Output is correct
38 Correct 25 ms 3448 KB Output is correct
39 Correct 20 ms 3448 KB Output is correct
40 Correct 22 ms 3448 KB Output is correct
41 Correct 25 ms 3448 KB Output is correct
42 Correct 11 ms 1912 KB Output is correct
43 Correct 12 ms 1912 KB Output is correct
44 Correct 12 ms 2040 KB Output is correct
45 Correct 26 ms 3576 KB Output is correct
46 Correct 23 ms 3576 KB Output is correct
47 Correct 20 ms 3576 KB Output is correct
48 Correct 16 ms 3192 KB Output is correct
49 Correct 15 ms 3064 KB Output is correct
50 Correct 12 ms 2680 KB Output is correct
51 Correct 29 ms 4216 KB Output is correct
52 Correct 31 ms 4216 KB Output is correct
53 Correct 19 ms 3960 KB Output is correct
54 Correct 7 ms 2168 KB Output is correct
55 Correct 7 ms 2168 KB Output is correct
56 Correct 16 ms 3448 KB Output is correct
57 Correct 7 ms 2424 KB Output is correct
58 Correct 14 ms 2168 KB Output is correct
59 Correct 15 ms 2296 KB Output is correct
60 Correct 17 ms 2296 KB Output is correct
61 Correct 15 ms 2552 KB Output is correct
62 Correct 22 ms 3580 KB Output is correct
63 Correct 45 ms 4724 KB Output is correct
64 Correct 45 ms 4596 KB Output is correct
65 Correct 51 ms 4724 KB Output is correct
66 Correct 92 ms 5612 KB Output is correct
67 Correct 61 ms 5608 KB Output is correct