답안 #370234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370234 2021-02-23T15:19:24 Z BartolM Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
371 ms 63196 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=3e4+5;

int n, m, pos0, pos1;
vector <pii> ls[N];
set <int> S[N];
set <pii> s;
int dist[N];

void dodaj(int a, int b, int c) {
//    printf("%d -> %d == %d\n", a, b, c);
    ls[a].pb(mp(b, c));
//    ls[b].pb(mp(a, c));
}

void dijkstra(int poc) {
    memset(dist, INF, sizeof dist);
    dist[poc]=0;
    s.insert(mp(0, poc));
    while (!s.empty()) {
        pii node=*s.begin();
        s.erase(s.begin());
        for (pii sus:ls[node.Y]) {
            if (sus.Y+node.X>=dist[sus.X]) continue;
            if (s.count(mp(dist[sus.X], sus.X))) s.erase(mp(dist[sus.X], sus.X));
            dist[sus.X]=sus.Y+node.X;
            s.insert(mp(dist[sus.X], sus.X));
        }
    }
}

void solve() {
    for (int i=0; i<n; ++i) {
        for (int x:S[i]) {
            for (int j=i+x; j<n; j+=x) {
                dodaj(i, j, (j-i)/x);
                if (S[j].count(x)) break;
            }
            for (int j=i-x; j>=0; j-=x) {
                dodaj(i, j, (i-j)/x);
                if (S[j].count(x)) break;
            }
        }
    }
    dijkstra(pos0);
    printf("%d\n", dist[pos1]==INF ? -1 : dist[pos1]);
}

void load() {
    scanf("%d %d", &n, &m);
    for (int i=0; i<m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        if (i==0) pos0=a;
        if (i==1) pos1=a;
        S[a].insert(b);
    }
}

int main() {
    load();
    solve();
    return 0;
}

Compilation message

skyscraper.cpp: In function 'void load()':
skyscraper.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2540 KB Output is correct
2 Correct 2 ms 2540 KB Output is correct
3 Correct 2 ms 2540 KB Output is correct
4 Correct 2 ms 2540 KB Output is correct
5 Correct 2 ms 2540 KB Output is correct
6 Correct 2 ms 2564 KB Output is correct
7 Correct 3 ms 2540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2540 KB Output is correct
2 Correct 2 ms 2540 KB Output is correct
3 Correct 2 ms 2540 KB Output is correct
4 Correct 2 ms 2540 KB Output is correct
5 Correct 2 ms 2540 KB Output is correct
6 Correct 2 ms 2540 KB Output is correct
7 Correct 2 ms 2540 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2540 KB Output is correct
10 Correct 2 ms 2540 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 2 ms 2540 KB Output is correct
13 Correct 2 ms 2540 KB Output is correct
14 Correct 3 ms 2688 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2540 KB Output is correct
2 Correct 2 ms 2540 KB Output is correct
3 Correct 2 ms 2496 KB Output is correct
4 Correct 2 ms 2540 KB Output is correct
5 Correct 2 ms 2540 KB Output is correct
6 Correct 3 ms 2540 KB Output is correct
7 Correct 2 ms 2540 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 3 ms 2540 KB Output is correct
10 Correct 3 ms 2540 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 3 ms 2540 KB Output is correct
13 Correct 2 ms 2540 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 4 ms 2668 KB Output is correct
16 Correct 3 ms 2668 KB Output is correct
17 Correct 5 ms 2816 KB Output is correct
18 Correct 3 ms 2816 KB Output is correct
19 Correct 3 ms 2796 KB Output is correct
20 Correct 4 ms 2668 KB Output is correct
21 Correct 3 ms 2668 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 3 ms 2668 KB Output is correct
24 Correct 5 ms 2796 KB Output is correct
25 Correct 4 ms 2796 KB Output is correct
26 Correct 4 ms 2668 KB Output is correct
27 Correct 3 ms 2668 KB Output is correct
28 Correct 3 ms 2924 KB Output is correct
29 Correct 9 ms 3308 KB Output is correct
30 Correct 5 ms 2796 KB Output is correct
31 Correct 6 ms 3052 KB Output is correct
32 Correct 5 ms 2944 KB Output is correct
33 Correct 14 ms 3820 KB Output is correct
34 Correct 14 ms 3820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2540 KB Output is correct
2 Correct 2 ms 2540 KB Output is correct
3 Correct 2 ms 2540 KB Output is correct
4 Correct 2 ms 2540 KB Output is correct
5 Correct 2 ms 2540 KB Output is correct
6 Correct 2 ms 2540 KB Output is correct
7 Correct 2 ms 2540 KB Output is correct
8 Correct 2 ms 2540 KB Output is correct
9 Correct 2 ms 2540 KB Output is correct
10 Correct 3 ms 2540 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 2 ms 2540 KB Output is correct
13 Correct 2 ms 2540 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 3 ms 2668 KB Output is correct
17 Correct 4 ms 2796 KB Output is correct
18 Correct 3 ms 2668 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 3 ms 2668 KB Output is correct
21 Correct 2 ms 2668 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 4 ms 2668 KB Output is correct
24 Correct 4 ms 2796 KB Output is correct
25 Correct 4 ms 2796 KB Output is correct
26 Correct 3 ms 2668 KB Output is correct
27 Correct 3 ms 2668 KB Output is correct
28 Correct 4 ms 2924 KB Output is correct
29 Correct 8 ms 3308 KB Output is correct
30 Correct 4 ms 2924 KB Output is correct
31 Correct 5 ms 3052 KB Output is correct
32 Correct 4 ms 2924 KB Output is correct
33 Correct 12 ms 3820 KB Output is correct
34 Correct 12 ms 3820 KB Output is correct
35 Correct 21 ms 4972 KB Output is correct
36 Correct 5 ms 3052 KB Output is correct
37 Correct 22 ms 5612 KB Output is correct
38 Correct 28 ms 5996 KB Output is correct
39 Correct 30 ms 5996 KB Output is correct
40 Correct 28 ms 5996 KB Output is correct
41 Correct 27 ms 5996 KB Output is correct
42 Correct 8 ms 2924 KB Output is correct
43 Correct 8 ms 2924 KB Output is correct
44 Correct 8 ms 2924 KB Output is correct
45 Correct 35 ms 8300 KB Output is correct
46 Correct 42 ms 8300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2540 KB Output is correct
2 Correct 2 ms 2540 KB Output is correct
3 Correct 2 ms 2540 KB Output is correct
4 Correct 2 ms 2540 KB Output is correct
5 Correct 2 ms 2540 KB Output is correct
6 Correct 2 ms 2540 KB Output is correct
7 Correct 2 ms 2540 KB Output is correct
8 Correct 2 ms 2540 KB Output is correct
9 Correct 2 ms 2540 KB Output is correct
10 Correct 2 ms 2540 KB Output is correct
11 Correct 3 ms 2668 KB Output is correct
12 Correct 2 ms 2540 KB Output is correct
13 Correct 2 ms 2540 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Correct 3 ms 2668 KB Output is correct
17 Correct 4 ms 2796 KB Output is correct
18 Correct 3 ms 2668 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 3 ms 2796 KB Output is correct
21 Correct 3 ms 2668 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 4 ms 2668 KB Output is correct
24 Correct 4 ms 2796 KB Output is correct
25 Correct 4 ms 2796 KB Output is correct
26 Correct 3 ms 2668 KB Output is correct
27 Correct 3 ms 2668 KB Output is correct
28 Correct 3 ms 2924 KB Output is correct
29 Correct 8 ms 3308 KB Output is correct
30 Correct 4 ms 2796 KB Output is correct
31 Correct 5 ms 3052 KB Output is correct
32 Correct 4 ms 2924 KB Output is correct
33 Correct 12 ms 3820 KB Output is correct
34 Correct 12 ms 3820 KB Output is correct
35 Correct 27 ms 4972 KB Output is correct
36 Correct 7 ms 3052 KB Output is correct
37 Correct 24 ms 5612 KB Output is correct
38 Correct 28 ms 5996 KB Output is correct
39 Correct 29 ms 5996 KB Output is correct
40 Correct 28 ms 5996 KB Output is correct
41 Correct 29 ms 5996 KB Output is correct
42 Correct 8 ms 2944 KB Output is correct
43 Correct 11 ms 2924 KB Output is correct
44 Correct 8 ms 2924 KB Output is correct
45 Correct 36 ms 8300 KB Output is correct
46 Correct 34 ms 8300 KB Output is correct
47 Correct 65 ms 12924 KB Output is correct
48 Correct 19 ms 6248 KB Output is correct
49 Correct 16 ms 5228 KB Output is correct
50 Correct 13 ms 4860 KB Output is correct
51 Correct 80 ms 8936 KB Output is correct
52 Correct 75 ms 9068 KB Output is correct
53 Correct 31 ms 6376 KB Output is correct
54 Correct 7 ms 3436 KB Output is correct
55 Correct 8 ms 3944 KB Output is correct
56 Correct 17 ms 5100 KB Output is correct
57 Correct 74 ms 11756 KB Output is correct
58 Correct 16 ms 4196 KB Output is correct
59 Correct 16 ms 4584 KB Output is correct
60 Correct 18 ms 5096 KB Output is correct
61 Correct 18 ms 4588 KB Output is correct
62 Correct 30 ms 9324 KB Output is correct
63 Correct 140 ms 25624 KB Output is correct
64 Correct 147 ms 28776 KB Output is correct
65 Correct 193 ms 38248 KB Output is correct
66 Correct 371 ms 63196 KB Output is correct
67 Correct 368 ms 63068 KB Output is correct