Submission #249247

# Submission time Handle Problem Language Result Execution time Memory
249247 2020-07-14T14:08:59 Z rdd6584 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
384 ms 126968 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int ,int> pii;


char visit[30000];
unordered_map<int,int> dist[30000];
int dp[30000][1000]; // 거리 100 이하일 때,
vector<int> v[30000];

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

    int st, ed;
    for (int i = 0; i < m; i++) {
        int a,b;
        scanf("%d %d" ,&a, &b);
        v[a].push_back(b);
        if (i==0) st = a;
        else if (i==1) ed = a;
    }

    memset(dp, -1, sizeof(dp));
    queue<pii> q;
    for (int i : v[st]) {
        if (i < 1000) dp[st][i] = 0;
        else dist[st][i] = 0;
        q.push({st, i});
    }

    while (!q.empty()) {
        pii tv = q.front();
        q.pop();

        int me;
        if (tv.second < 1000) me = dp[tv.first][tv.second];
        else me = dist[tv.first][tv.second];

        if (tv.first == ed) return !printf("%d", me);
        int ne;

        if (tv.second < 1000) {
            for (int dir = -1; dir <= 1; dir += 2) {
                ne = tv.first + dir * tv.second;
                if (ne < 0 || ne >= n) continue;
                if (dp[ne][tv.second] == -1) {
                    int flag = 0;
                    if (!visit[ne]) {
                        visit[ne] = 1;
                        for (int i : v[ne]) {
                            if (i < 1000) dp[ne][i] = me + 1;
                            else dist[ne][i] = me + 1;
                            q.push({ne, i});
                            flag |= i == tv.second;
                        }
                    }
                    if (!flag) {
                        q.push({ne, tv.second});
                        dp[ne][tv.second] = me + 1;
                    }
                }
            }
        }
        else {
            for (int dir = -1; dir <= 1; dir += 2) {
                ne = tv.first + dir * tv.second;
                if (ne < 0 || ne >= n) continue;
                if (dist[ne].find(tv.second) == dist[ne].end()) {
                    int flag = 0;
                    if (!visit[ne]) {
                        visit[ne] = 1;
                        for (int i : v[ne]) {
                            if (i < 1000) dp[ne][i] = me + 1;
                            else dist[ne][i] = me + 1;
                            q.push({ne, i});
                            flag |= i == tv.second;
                        }
                    }
                    if (!flag) {
                        q.push({ne, tv.second});
                        dist[ne][tv.second] = me + 1;
                    }
                }
            }
        }
    }
    printf("-1");
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:13: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:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d" ,&a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:15:9: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int st, ed;
         ^~
skyscraper.cpp:40:9: warning: 'ed' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (tv.first == ed) return !printf("%d", me);
         ^~
# Verdict Execution time Memory Grader output
1 Correct 57 ms 120056 KB Output is correct
2 Correct 57 ms 120056 KB Output is correct
3 Correct 58 ms 120056 KB Output is correct
4 Correct 62 ms 120056 KB Output is correct
5 Correct 62 ms 120120 KB Output is correct
6 Correct 69 ms 120120 KB Output is correct
7 Correct 63 ms 120056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 120056 KB Output is correct
2 Correct 60 ms 120056 KB Output is correct
3 Correct 66 ms 120056 KB Output is correct
4 Correct 62 ms 120056 KB Output is correct
5 Correct 67 ms 120056 KB Output is correct
6 Correct 69 ms 120056 KB Output is correct
7 Correct 62 ms 120060 KB Output is correct
8 Correct 64 ms 120060 KB Output is correct
9 Correct 62 ms 120056 KB Output is correct
10 Correct 64 ms 120056 KB Output is correct
11 Correct 64 ms 120056 KB Output is correct
12 Correct 64 ms 120184 KB Output is correct
13 Correct 63 ms 120076 KB Output is correct
14 Correct 67 ms 120184 KB Output is correct
15 Correct 63 ms 120056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 120056 KB Output is correct
2 Correct 62 ms 120056 KB Output is correct
3 Correct 64 ms 120056 KB Output is correct
4 Correct 64 ms 120056 KB Output is correct
5 Correct 64 ms 120056 KB Output is correct
6 Correct 65 ms 120056 KB Output is correct
7 Correct 62 ms 120056 KB Output is correct
8 Correct 63 ms 120184 KB Output is correct
9 Correct 65 ms 120056 KB Output is correct
10 Correct 64 ms 120044 KB Output is correct
11 Correct 63 ms 120056 KB Output is correct
12 Correct 64 ms 120184 KB Output is correct
13 Correct 64 ms 120184 KB Output is correct
14 Correct 63 ms 120056 KB Output is correct
15 Correct 69 ms 120056 KB Output is correct
16 Correct 64 ms 120056 KB Output is correct
17 Correct 68 ms 120184 KB Output is correct
18 Correct 72 ms 120056 KB Output is correct
19 Correct 66 ms 120056 KB Output is correct
20 Correct 65 ms 120184 KB Output is correct
21 Correct 69 ms 120184 KB Output is correct
22 Correct 67 ms 120056 KB Output is correct
23 Correct 63 ms 120184 KB Output is correct
24 Correct 66 ms 120184 KB Output is correct
25 Correct 72 ms 120184 KB Output is correct
26 Correct 63 ms 120056 KB Output is correct
27 Correct 65 ms 120184 KB Output is correct
28 Correct 65 ms 120224 KB Output is correct
29 Correct 65 ms 120056 KB Output is correct
30 Correct 70 ms 120056 KB Output is correct
31 Correct 65 ms 120056 KB Output is correct
32 Correct 71 ms 120184 KB Output is correct
33 Correct 67 ms 120056 KB Output is correct
34 Correct 67 ms 120184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 120056 KB Output is correct
2 Correct 63 ms 120056 KB Output is correct
3 Correct 66 ms 120056 KB Output is correct
4 Correct 67 ms 120056 KB Output is correct
5 Correct 61 ms 120056 KB Output is correct
6 Correct 63 ms 120056 KB Output is correct
7 Correct 62 ms 120056 KB Output is correct
8 Correct 63 ms 120056 KB Output is correct
9 Correct 67 ms 120056 KB Output is correct
10 Correct 65 ms 120056 KB Output is correct
11 Correct 64 ms 120056 KB Output is correct
12 Correct 64 ms 120056 KB Output is correct
13 Correct 64 ms 120056 KB Output is correct
14 Correct 63 ms 120056 KB Output is correct
15 Correct 63 ms 120056 KB Output is correct
16 Correct 63 ms 120056 KB Output is correct
17 Correct 70 ms 120184 KB Output is correct
18 Correct 65 ms 120056 KB Output is correct
19 Correct 63 ms 120060 KB Output is correct
20 Correct 64 ms 120184 KB Output is correct
21 Correct 63 ms 120060 KB Output is correct
22 Correct 62 ms 120056 KB Output is correct
23 Correct 71 ms 120184 KB Output is correct
24 Correct 64 ms 120184 KB Output is correct
25 Correct 65 ms 120184 KB Output is correct
26 Correct 65 ms 120184 KB Output is correct
27 Correct 63 ms 120184 KB Output is correct
28 Correct 67 ms 120280 KB Output is correct
29 Correct 66 ms 120056 KB Output is correct
30 Correct 64 ms 120056 KB Output is correct
31 Correct 65 ms 120184 KB Output is correct
32 Correct 65 ms 120056 KB Output is correct
33 Correct 66 ms 120056 KB Output is correct
34 Correct 70 ms 120184 KB Output is correct
35 Correct 76 ms 121328 KB Output is correct
36 Correct 65 ms 120184 KB Output is correct
37 Correct 77 ms 120568 KB Output is correct
38 Correct 76 ms 121720 KB Output is correct
39 Correct 74 ms 120568 KB Output is correct
40 Correct 73 ms 120824 KB Output is correct
41 Correct 78 ms 121464 KB Output is correct
42 Correct 72 ms 120568 KB Output is correct
43 Correct 70 ms 120696 KB Output is correct
44 Correct 69 ms 120696 KB Output is correct
45 Correct 82 ms 120696 KB Output is correct
46 Correct 78 ms 120696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 120056 KB Output is correct
2 Correct 62 ms 120056 KB Output is correct
3 Correct 70 ms 120056 KB Output is correct
4 Correct 62 ms 120056 KB Output is correct
5 Correct 63 ms 120056 KB Output is correct
6 Correct 63 ms 120060 KB Output is correct
7 Correct 64 ms 120056 KB Output is correct
8 Correct 63 ms 120056 KB Output is correct
9 Correct 64 ms 120056 KB Output is correct
10 Correct 64 ms 120056 KB Output is correct
11 Correct 65 ms 120056 KB Output is correct
12 Correct 66 ms 120056 KB Output is correct
13 Correct 65 ms 120056 KB Output is correct
14 Correct 63 ms 120176 KB Output is correct
15 Correct 65 ms 120056 KB Output is correct
16 Correct 63 ms 120092 KB Output is correct
17 Correct 65 ms 120184 KB Output is correct
18 Correct 65 ms 120184 KB Output is correct
19 Correct 63 ms 120056 KB Output is correct
20 Correct 64 ms 120184 KB Output is correct
21 Correct 64 ms 120056 KB Output is correct
22 Correct 63 ms 120060 KB Output is correct
23 Correct 66 ms 120184 KB Output is correct
24 Correct 64 ms 120184 KB Output is correct
25 Correct 66 ms 120184 KB Output is correct
26 Correct 62 ms 120056 KB Output is correct
27 Correct 65 ms 120184 KB Output is correct
28 Correct 65 ms 120156 KB Output is correct
29 Correct 66 ms 120056 KB Output is correct
30 Correct 68 ms 120044 KB Output is correct
31 Correct 63 ms 120056 KB Output is correct
32 Correct 64 ms 120064 KB Output is correct
33 Correct 67 ms 120056 KB Output is correct
34 Correct 66 ms 120056 KB Output is correct
35 Correct 78 ms 121336 KB Output is correct
36 Correct 66 ms 120184 KB Output is correct
37 Correct 69 ms 120568 KB Output is correct
38 Correct 77 ms 121760 KB Output is correct
39 Correct 78 ms 120644 KB Output is correct
40 Correct 77 ms 120824 KB Output is correct
41 Correct 77 ms 121464 KB Output is correct
42 Correct 69 ms 120568 KB Output is correct
43 Correct 69 ms 120696 KB Output is correct
44 Correct 71 ms 120696 KB Output is correct
45 Correct 84 ms 120700 KB Output is correct
46 Correct 74 ms 120696 KB Output is correct
47 Correct 75 ms 121592 KB Output is correct
48 Correct 70 ms 120824 KB Output is correct
49 Correct 71 ms 120824 KB Output is correct
50 Correct 68 ms 120568 KB Output is correct
51 Correct 91 ms 123512 KB Output is correct
52 Correct 98 ms 124024 KB Output is correct
53 Correct 76 ms 121336 KB Output is correct
54 Correct 65 ms 120184 KB Output is correct
55 Correct 67 ms 120056 KB Output is correct
56 Correct 76 ms 121208 KB Output is correct
57 Correct 63 ms 120184 KB Output is correct
58 Correct 77 ms 120568 KB Output is correct
59 Correct 73 ms 120568 KB Output is correct
60 Correct 73 ms 120568 KB Output is correct
61 Correct 75 ms 120892 KB Output is correct
62 Correct 144 ms 126968 KB Output is correct
63 Correct 201 ms 120824 KB Output is correct
64 Correct 227 ms 120696 KB Output is correct
65 Correct 269 ms 120696 KB Output is correct
66 Correct 384 ms 120696 KB Output is correct
67 Correct 212 ms 120696 KB Output is correct