답안 #158241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158241 2019-10-15T17:06:01 Z Akashi Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
260 ms 65636 KB
#include <bits/stdc++.h>
using namespace std;

int sgn[] = {-1, 1};
int n, m, pos;
int d[30005];
bool viz[30005];
set <int> s[30005];
vector <pair <int, int> > v[30005];
priority_queue <pair <int, int>, vector <pair <int, int> >, greater <pair <int, int> > > q;

int main()
{
    scanf("%d%d", &n, &m);

    int x2, x, y;
    scanf("%d%d", &x, &y);
    s[x].insert(y); x2 = x;
    scanf("%d%d", &x, &y);
    pos = x;

    if(pos == x2){
        printf("0");
        return 0;
    }

    for(int i = 3; i <= m ; ++i){
        scanf("%d%d", &x, &y);
        s[x].insert(y);
    }

    for(int i = 0; i < n ; ++i){
        d[i] = 1e9;
        if(s[i].empty()) continue ;

        for(auto it : s[i]){
            int nod = i, x = i, y = it, k = 1;
            while(x + y < n){
                v[nod].push_back({x + y, k});

                x += y; ++k;
                if(s[x].find(y) != s[x].end()) break ;
            }

            x = i; k = 1;
            while(x - y >= 0){
                v[nod].push_back({x - y, k});

                x -= y; ++k;
                if(s[x].find(y) != s[x].end()) break ;
            }
        }
    }

    q.push({0, x2});
    d[x2] = 0;
    while(!q.empty()){
        int l = q.top().first, nod = q.top().second;
        if(pos == nod){
            printf("%d", l);
            return 0;
        }

        q.pop();
        if(viz[nod]) continue ;
        viz[nod] = 1;

        for(auto it : v[nod]){
            if(d[it.first] > l + it.second){
                d[it.first] = l + it.second;
                q.push({l + it.second, it.first});
            }
        }
    }

    printf("-1");

    return 0;
}

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:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &x, &y);
     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &x, &y);
     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2428 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2428 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2428 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
8 Correct 4 ms 2424 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2424 KB Output is correct
11 Correct 5 ms 2552 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 4 ms 2424 KB Output is correct
14 Correct 5 ms 2524 KB Output is correct
15 Correct 5 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2424 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
8 Correct 4 ms 2424 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2552 KB Output is correct
11 Correct 5 ms 2552 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 4 ms 2424 KB Output is correct
14 Correct 5 ms 2552 KB Output is correct
15 Correct 5 ms 2552 KB Output is correct
16 Correct 4 ms 2552 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 4 ms 2552 KB Output is correct
19 Correct 4 ms 2552 KB Output is correct
20 Correct 4 ms 2552 KB Output is correct
21 Correct 4 ms 2552 KB Output is correct
22 Correct 4 ms 2552 KB Output is correct
23 Correct 5 ms 2552 KB Output is correct
24 Correct 5 ms 2680 KB Output is correct
25 Correct 5 ms 2680 KB Output is correct
26 Correct 4 ms 2552 KB Output is correct
27 Correct 4 ms 2552 KB Output is correct
28 Correct 5 ms 2812 KB Output is correct
29 Correct 7 ms 3320 KB Output is correct
30 Correct 5 ms 2808 KB Output is correct
31 Correct 6 ms 2936 KB Output is correct
32 Correct 5 ms 2812 KB Output is correct
33 Correct 10 ms 4088 KB Output is correct
34 Correct 9 ms 3960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 5 ms 2424 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
8 Correct 3 ms 2424 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2552 KB Output is correct
11 Correct 3 ms 2552 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 4 ms 2424 KB Output is correct
14 Correct 5 ms 2552 KB Output is correct
15 Correct 5 ms 2552 KB Output is correct
16 Correct 4 ms 2552 KB Output is correct
17 Correct 6 ms 2756 KB Output is correct
18 Correct 5 ms 2552 KB Output is correct
19 Correct 4 ms 2552 KB Output is correct
20 Correct 5 ms 2552 KB Output is correct
21 Correct 4 ms 2524 KB Output is correct
22 Correct 4 ms 2552 KB Output is correct
23 Correct 5 ms 2552 KB Output is correct
24 Correct 5 ms 2680 KB Output is correct
25 Correct 5 ms 2680 KB Output is correct
26 Correct 4 ms 2552 KB Output is correct
27 Correct 4 ms 2552 KB Output is correct
28 Correct 5 ms 2680 KB Output is correct
29 Correct 7 ms 3320 KB Output is correct
30 Correct 5 ms 2808 KB Output is correct
31 Correct 7 ms 2936 KB Output is correct
32 Correct 6 ms 2808 KB Output is correct
33 Correct 10 ms 3960 KB Output is correct
34 Correct 9 ms 3964 KB Output is correct
35 Correct 25 ms 4728 KB Output is correct
36 Correct 7 ms 2836 KB Output is correct
37 Correct 27 ms 5460 KB Output is correct
38 Correct 32 ms 5628 KB Output is correct
39 Correct 32 ms 5624 KB Output is correct
40 Correct 32 ms 5624 KB Output is correct
41 Correct 31 ms 5624 KB Output is correct
42 Correct 9 ms 2552 KB Output is correct
43 Correct 9 ms 2552 KB Output is correct
44 Correct 9 ms 2680 KB Output is correct
45 Correct 33 ms 8312 KB Output is correct
46 Correct 32 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2424 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
8 Correct 4 ms 2424 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2424 KB Output is correct
11 Correct 5 ms 2680 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
13 Correct 4 ms 2424 KB Output is correct
14 Correct 5 ms 2552 KB Output is correct
15 Correct 5 ms 2556 KB Output is correct
16 Correct 5 ms 2552 KB Output is correct
17 Correct 5 ms 2808 KB Output is correct
18 Correct 4 ms 2552 KB Output is correct
19 Correct 4 ms 2552 KB Output is correct
20 Correct 5 ms 2552 KB Output is correct
21 Correct 4 ms 2552 KB Output is correct
22 Correct 4 ms 2524 KB Output is correct
23 Correct 5 ms 2552 KB Output is correct
24 Correct 5 ms 2680 KB Output is correct
25 Correct 5 ms 2552 KB Output is correct
26 Correct 4 ms 2552 KB Output is correct
27 Correct 5 ms 2552 KB Output is correct
28 Correct 5 ms 2808 KB Output is correct
29 Correct 7 ms 3320 KB Output is correct
30 Correct 5 ms 2680 KB Output is correct
31 Correct 6 ms 2936 KB Output is correct
32 Correct 5 ms 2808 KB Output is correct
33 Correct 11 ms 3960 KB Output is correct
34 Correct 9 ms 3960 KB Output is correct
35 Correct 25 ms 4768 KB Output is correct
36 Correct 7 ms 2936 KB Output is correct
37 Correct 27 ms 5496 KB Output is correct
38 Correct 33 ms 5624 KB Output is correct
39 Correct 34 ms 5596 KB Output is correct
40 Correct 32 ms 5624 KB Output is correct
41 Correct 32 ms 5624 KB Output is correct
42 Correct 9 ms 2552 KB Output is correct
43 Correct 10 ms 2552 KB Output is correct
44 Correct 10 ms 2552 KB Output is correct
45 Correct 34 ms 8440 KB Output is correct
46 Correct 31 ms 8312 KB Output is correct
47 Correct 57 ms 12788 KB Output is correct
48 Correct 24 ms 6004 KB Output is correct
49 Correct 20 ms 4984 KB Output is correct
50 Correct 16 ms 4732 KB Output is correct
51 Correct 40 ms 7940 KB Output is correct
52 Correct 42 ms 8380 KB Output is correct
53 Correct 20 ms 4724 KB Output is correct
54 Correct 6 ms 2936 KB Output is correct
55 Correct 7 ms 3316 KB Output is correct
56 Correct 20 ms 5112 KB Output is correct
57 Correct 22 ms 11384 KB Output is correct
58 Correct 13 ms 3312 KB Output is correct
59 Correct 14 ms 3956 KB Output is correct
60 Correct 15 ms 4468 KB Output is correct
61 Correct 15 ms 3960 KB Output is correct
62 Correct 31 ms 8824 KB Output is correct
63 Correct 97 ms 25836 KB Output is correct
64 Correct 110 ms 29716 KB Output is correct
65 Correct 146 ms 39024 KB Output is correct
66 Correct 260 ms 65612 KB Output is correct
67 Correct 215 ms 65636 KB Output is correct