답안 #109948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109948 2019-05-08T12:36:28 Z PeppaPig Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
509 ms 190100 KB
#include <bits/stdc++.h>

#define pii pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 3e4+5;
const int M = 2e3+5;

int n, m, st, en;
int d[N], chk[N][M];
vector<int> B[N];

int main() {
    fill_n(d, N, 1e9);
    scanf("%d %d", &n, &m);
    for(int i = 0, b, p; i < m; i++) {
        scanf("%d %d", &b, &p); 
        B[b].emplace_back(p);
        if(i == 0) st = b;
        if(i == 1) en = b;
    }
    for(int i = 0; i < n; i++) {
        sort(B[i].begin(), B[i].end());
        B[i].resize(unique(B[i].begin(), B[i].end()) - B[i].begin());
    }
    priority_queue<pii, vector<pii>, greater<pii> > Q;
    Q.emplace(d[st] = 0, st);
    while(!Q.empty()) {
        pii now = Q.top(); Q.pop();
        if(d[now.y] != now.x) continue;
        int u = now.y;
        for(int p : B[u]) {
            for(int i = u + p, cnt = 1; i < n; i += p, cnt++) {
                if(p < M && chk[i][p]) break;
                if(d[i] > d[u] + cnt) {
                    Q.emplace(d[i] = d[u] + cnt, i);
                    if(p < M) chk[i][p] = true;
                }
            }
            for(int i = u - p, cnt = 1; i >= 0; i -= p, cnt++) {
                if(p < M && chk[i][p]) break;
                if(d[i] > d[u] + cnt) {
                    Q.emplace(d[i] = d[u] + cnt, i);
                    if(p < M) chk[i][p] = true;
                }
            }
        }
    }
    if(d[en] != 1e9) printf("%d\n", d[en]);
    else printf("-1\n");

    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:18: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:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &b, &p); 
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 4 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1196 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1280 KB Output is correct
9 Correct 4 ms 1408 KB Output is correct
10 Correct 4 ms 1536 KB Output is correct
11 Correct 4 ms 1536 KB Output is correct
12 Correct 3 ms 1536 KB Output is correct
13 Correct 4 ms 1536 KB Output is correct
14 Correct 3 ms 1536 KB Output is correct
15 Correct 4 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1280 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 4 ms 1536 KB Output is correct
11 Correct 4 ms 1536 KB Output is correct
12 Correct 4 ms 1536 KB Output is correct
13 Correct 4 ms 1536 KB Output is correct
14 Correct 4 ms 1536 KB Output is correct
15 Correct 4 ms 1536 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 27 ms 4480 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 3 ms 1152 KB Output is correct
20 Correct 13 ms 9316 KB Output is correct
21 Correct 4 ms 1152 KB Output is correct
22 Correct 4 ms 1152 KB Output is correct
23 Correct 13 ms 7808 KB Output is correct
24 Correct 14 ms 9984 KB Output is correct
25 Correct 15 ms 11392 KB Output is correct
26 Correct 11 ms 9216 KB Output is correct
27 Correct 11 ms 9216 KB Output is correct
28 Correct 14 ms 9216 KB Output is correct
29 Correct 15 ms 9728 KB Output is correct
30 Correct 12 ms 9472 KB Output is correct
31 Correct 13 ms 9600 KB Output is correct
32 Correct 13 ms 9600 KB Output is correct
33 Correct 16 ms 9984 KB Output is correct
34 Correct 16 ms 9984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1124 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1280 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 4 ms 1536 KB Output is correct
11 Correct 4 ms 1536 KB Output is correct
12 Correct 4 ms 1536 KB Output is correct
13 Correct 4 ms 1536 KB Output is correct
14 Correct 4 ms 1664 KB Output is correct
15 Correct 4 ms 1536 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 9 ms 4480 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 4 ms 1280 KB Output is correct
20 Correct 12 ms 9216 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 11 ms 7808 KB Output is correct
24 Correct 16 ms 10012 KB Output is correct
25 Correct 16 ms 11392 KB Output is correct
26 Correct 11 ms 9216 KB Output is correct
27 Correct 12 ms 9216 KB Output is correct
28 Correct 12 ms 9216 KB Output is correct
29 Correct 15 ms 9728 KB Output is correct
30 Correct 14 ms 9472 KB Output is correct
31 Correct 16 ms 9600 KB Output is correct
32 Correct 15 ms 9728 KB Output is correct
33 Correct 19 ms 9984 KB Output is correct
34 Correct 16 ms 9984 KB Output is correct
35 Correct 22 ms 8960 KB Output is correct
36 Correct 10 ms 6400 KB Output is correct
37 Correct 23 ms 12032 KB Output is correct
38 Correct 27 ms 13048 KB Output is correct
39 Correct 31 ms 12544 KB Output is correct
40 Correct 27 ms 13560 KB Output is correct
41 Correct 30 ms 12948 KB Output is correct
42 Correct 18 ms 9472 KB Output is correct
43 Correct 16 ms 9472 KB Output is correct
44 Correct 16 ms 9464 KB Output is correct
45 Correct 25 ms 11388 KB Output is correct
46 Correct 26 ms 11380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 2 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1280 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 4 ms 1536 KB Output is correct
11 Correct 5 ms 1508 KB Output is correct
12 Correct 4 ms 1536 KB Output is correct
13 Correct 4 ms 1536 KB Output is correct
14 Correct 4 ms 1664 KB Output is correct
15 Correct 4 ms 1664 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 7 ms 4480 KB Output is correct
18 Correct 4 ms 1152 KB Output is correct
19 Correct 3 ms 1280 KB Output is correct
20 Correct 13 ms 9216 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 3 ms 1152 KB Output is correct
23 Correct 12 ms 7736 KB Output is correct
24 Correct 15 ms 9984 KB Output is correct
25 Correct 17 ms 11392 KB Output is correct
26 Correct 13 ms 9344 KB Output is correct
27 Correct 15 ms 9216 KB Output is correct
28 Correct 15 ms 9216 KB Output is correct
29 Correct 15 ms 9684 KB Output is correct
30 Correct 15 ms 9472 KB Output is correct
31 Correct 14 ms 9600 KB Output is correct
32 Correct 13 ms 9600 KB Output is correct
33 Correct 16 ms 9984 KB Output is correct
34 Correct 16 ms 9984 KB Output is correct
35 Correct 22 ms 8952 KB Output is correct
36 Correct 10 ms 6400 KB Output is correct
37 Correct 24 ms 12032 KB Output is correct
38 Correct 26 ms 13056 KB Output is correct
39 Correct 27 ms 12416 KB Output is correct
40 Correct 29 ms 13440 KB Output is correct
41 Correct 29 ms 12892 KB Output is correct
42 Correct 19 ms 9532 KB Output is correct
43 Correct 18 ms 9472 KB Output is correct
44 Correct 16 ms 9436 KB Output is correct
45 Correct 35 ms 11388 KB Output is correct
46 Correct 25 ms 11388 KB Output is correct
47 Correct 138 ms 82292 KB Output is correct
48 Correct 12 ms 1536 KB Output is correct
49 Correct 11 ms 1664 KB Output is correct
50 Correct 13 ms 1536 KB Output is correct
51 Correct 209 ms 159960 KB Output is correct
52 Correct 199 ms 147056 KB Output is correct
53 Correct 143 ms 119032 KB Output is correct
54 Correct 182 ms 61788 KB Output is correct
55 Correct 98 ms 81784 KB Output is correct
56 Correct 148 ms 122872 KB Output is correct
57 Correct 176 ms 128232 KB Output is correct
58 Correct 140 ms 121952 KB Output is correct
59 Correct 143 ms 122144 KB Output is correct
60 Correct 173 ms 123000 KB Output is correct
61 Correct 159 ms 122844 KB Output is correct
62 Correct 108 ms 39508 KB Output is correct
63 Correct 296 ms 190100 KB Output is correct
64 Correct 306 ms 174056 KB Output is correct
65 Correct 340 ms 163544 KB Output is correct
66 Correct 465 ms 153732 KB Output is correct
67 Correct 509 ms 153716 KB Output is correct