답안 #52654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52654 2018-06-26T10:41:26 Z evpipis Jakarta Skyscrapers (APIO15_skyscraper) C++11
100 / 100
321 ms 45132 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;

const int len = 30005, inf = 1e9;
int po[len], pos[len], vis[len], dis[len][180][2];
vector<int> vec[len];
//map<int, int> mymap[len];
deque<pair<ii, ii> > deq;

int main(){
    int n, m, k;
    scanf("%d %d", &n, &m);
    k = sqrt(n)+1;
    for (int i = 0; i < m; i++)
        scanf("%d %d", &pos[i], &po[i]);
    for (int i = 0; i < m; i++)
        vec[pos[i]].pb(po[i]);

    for (int i = 0; i < n; i++)
        for (int j = 0; j <= k; j++)
            dis[i][j][0] = dis[i][j][1] = inf;

    int ans = -1;
    deq.pb(mp(mp(0, 0), mp(pos[0], po[0])));
    deq.pb(mp(mp(0, 1), mp(pos[0], po[0])));
    while (!deq.empty()){
        pair<ii, ii> top = deq.front();
        deq.pop_front();

        int d = top.fi.fi, t = top.fi.se, b = top.se.fi, p = top.se.se;
        if (b == pos[1]){
            ans = d;
            break;
        }

        //if (mymap[b].count(p)) continue;
        //mymap[b][p] = d;
        if (p <= k && dis[b][p][t] != inf)
            continue;
        if (p <= k)
            dis[b][p][t] = d;

        if (t == 0 && b-p >= 0)
            deq.pb(mp(mp(d+1, t), mp(b-p, p)));
        if (t == 1 && b+p < n)
            deq.pb(mp(mp(d+1, t), mp(b+p, p)));

        if (vis[b]) continue;
        vis[b] = 1;
        for (int j = 0; j < vec[b].size(); j++){
            deq.push_front(mp(mp(d, 0), mp(b, vec[b][j])));
            deq.push_front(mp(mp(d, 1), mp(b, vec[b][j])));
        }
    }

    printf("%d\n", ans);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:56:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vec[b].size(); j++){
                         ~~^~~~~~~~~~~~~~~
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:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &pos[i], &po[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1164 KB Output is correct
4 Correct 3 ms 1188 KB Output is correct
5 Correct 2 ms 1188 KB Output is correct
6 Correct 3 ms 1276 KB Output is correct
7 Correct 3 ms 1276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1276 KB Output is correct
2 Correct 3 ms 1276 KB Output is correct
3 Correct 3 ms 1276 KB Output is correct
4 Correct 3 ms 1276 KB Output is correct
5 Correct 3 ms 1276 KB Output is correct
6 Correct 3 ms 1276 KB Output is correct
7 Correct 2 ms 1340 KB Output is correct
8 Correct 2 ms 1340 KB Output is correct
9 Correct 3 ms 1388 KB Output is correct
10 Correct 3 ms 1388 KB Output is correct
11 Correct 4 ms 1644 KB Output is correct
12 Correct 3 ms 1644 KB Output is correct
13 Correct 4 ms 1644 KB Output is correct
14 Correct 4 ms 1644 KB Output is correct
15 Correct 3 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1644 KB Output is correct
2 Correct 3 ms 1644 KB Output is correct
3 Correct 3 ms 1644 KB Output is correct
4 Correct 3 ms 1644 KB Output is correct
5 Correct 3 ms 1644 KB Output is correct
6 Correct 3 ms 1644 KB Output is correct
7 Correct 3 ms 1644 KB Output is correct
8 Correct 3 ms 1644 KB Output is correct
9 Correct 4 ms 1644 KB Output is correct
10 Correct 3 ms 1644 KB Output is correct
11 Correct 3 ms 1644 KB Output is correct
12 Correct 3 ms 1644 KB Output is correct
13 Correct 4 ms 1644 KB Output is correct
14 Correct 3 ms 1644 KB Output is correct
15 Correct 3 ms 1644 KB Output is correct
16 Correct 3 ms 1644 KB Output is correct
17 Correct 5 ms 2428 KB Output is correct
18 Correct 5 ms 3836 KB Output is correct
19 Correct 6 ms 4092 KB Output is correct
20 Correct 6 ms 4220 KB Output is correct
21 Correct 4 ms 4220 KB Output is correct
22 Correct 5 ms 4220 KB Output is correct
23 Correct 5 ms 4220 KB Output is correct
24 Correct 5 ms 4220 KB Output is correct
25 Correct 6 ms 4220 KB Output is correct
26 Correct 5 ms 4220 KB Output is correct
27 Correct 5 ms 4220 KB Output is correct
28 Correct 5 ms 4220 KB Output is correct
29 Correct 5 ms 4220 KB Output is correct
30 Correct 4 ms 4220 KB Output is correct
31 Correct 6 ms 4220 KB Output is correct
32 Correct 5 ms 4220 KB Output is correct
33 Correct 7 ms 4220 KB Output is correct
34 Correct 6 ms 4332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4332 KB Output is correct
2 Correct 2 ms 4332 KB Output is correct
3 Correct 3 ms 4332 KB Output is correct
4 Correct 2 ms 4332 KB Output is correct
5 Correct 3 ms 4332 KB Output is correct
6 Correct 4 ms 4332 KB Output is correct
7 Correct 3 ms 4332 KB Output is correct
8 Correct 3 ms 4332 KB Output is correct
9 Correct 3 ms 4332 KB Output is correct
10 Correct 3 ms 4332 KB Output is correct
11 Correct 3 ms 4332 KB Output is correct
12 Correct 4 ms 4332 KB Output is correct
13 Correct 3 ms 4332 KB Output is correct
14 Correct 3 ms 4332 KB Output is correct
15 Correct 3 ms 4332 KB Output is correct
16 Correct 3 ms 4332 KB Output is correct
17 Correct 4 ms 4332 KB Output is correct
18 Correct 5 ms 4332 KB Output is correct
19 Correct 4 ms 4332 KB Output is correct
20 Correct 7 ms 4332 KB Output is correct
21 Correct 3 ms 4332 KB Output is correct
22 Correct 6 ms 4332 KB Output is correct
23 Correct 5 ms 4332 KB Output is correct
24 Correct 6 ms 4332 KB Output is correct
25 Correct 6 ms 4332 KB Output is correct
26 Correct 5 ms 4332 KB Output is correct
27 Correct 6 ms 4332 KB Output is correct
28 Correct 6 ms 4332 KB Output is correct
29 Correct 7 ms 4332 KB Output is correct
30 Correct 5 ms 4332 KB Output is correct
31 Correct 7 ms 4332 KB Output is correct
32 Correct 5 ms 4332 KB Output is correct
33 Correct 7 ms 4332 KB Output is correct
34 Correct 6 ms 4332 KB Output is correct
35 Correct 15 ms 4332 KB Output is correct
36 Correct 5 ms 4332 KB Output is correct
37 Correct 12 ms 4768 KB Output is correct
38 Correct 13 ms 4788 KB Output is correct
39 Correct 15 ms 4788 KB Output is correct
40 Correct 14 ms 4788 KB Output is correct
41 Correct 13 ms 4788 KB Output is correct
42 Correct 17 ms 4788 KB Output is correct
43 Correct 10 ms 4788 KB Output is correct
44 Correct 12 ms 5488 KB Output is correct
45 Correct 19 ms 5488 KB Output is correct
46 Correct 18 ms 5488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5488 KB Output is correct
2 Correct 2 ms 5488 KB Output is correct
3 Correct 2 ms 5488 KB Output is correct
4 Correct 2 ms 5488 KB Output is correct
5 Correct 3 ms 5488 KB Output is correct
6 Correct 3 ms 5488 KB Output is correct
7 Correct 3 ms 5488 KB Output is correct
8 Correct 3 ms 5488 KB Output is correct
9 Correct 2 ms 5488 KB Output is correct
10 Correct 3 ms 5488 KB Output is correct
11 Correct 3 ms 5488 KB Output is correct
12 Correct 3 ms 5488 KB Output is correct
13 Correct 3 ms 5488 KB Output is correct
14 Correct 4 ms 5488 KB Output is correct
15 Correct 4 ms 5488 KB Output is correct
16 Correct 3 ms 5488 KB Output is correct
17 Correct 4 ms 5488 KB Output is correct
18 Correct 4 ms 5488 KB Output is correct
19 Correct 5 ms 5488 KB Output is correct
20 Correct 6 ms 5488 KB Output is correct
21 Correct 4 ms 5488 KB Output is correct
22 Correct 4 ms 5488 KB Output is correct
23 Correct 4 ms 5488 KB Output is correct
24 Correct 5 ms 5488 KB Output is correct
25 Correct 5 ms 5488 KB Output is correct
26 Correct 5 ms 5488 KB Output is correct
27 Correct 6 ms 5488 KB Output is correct
28 Correct 7 ms 5488 KB Output is correct
29 Correct 6 ms 5488 KB Output is correct
30 Correct 5 ms 5488 KB Output is correct
31 Correct 6 ms 5488 KB Output is correct
32 Correct 6 ms 5488 KB Output is correct
33 Correct 9 ms 5488 KB Output is correct
34 Correct 7 ms 5488 KB Output is correct
35 Correct 17 ms 5488 KB Output is correct
36 Correct 5 ms 5488 KB Output is correct
37 Correct 10 ms 5488 KB Output is correct
38 Correct 13 ms 5488 KB Output is correct
39 Correct 12 ms 5488 KB Output is correct
40 Correct 17 ms 5488 KB Output is correct
41 Correct 15 ms 5488 KB Output is correct
42 Correct 10 ms 5488 KB Output is correct
43 Correct 11 ms 5488 KB Output is correct
44 Correct 14 ms 5500 KB Output is correct
45 Correct 20 ms 5500 KB Output is correct
46 Correct 18 ms 5500 KB Output is correct
47 Correct 24 ms 19712 KB Output is correct
48 Correct 35 ms 34684 KB Output is correct
49 Correct 38 ms 37628 KB Output is correct
50 Correct 39 ms 41108 KB Output is correct
51 Correct 50 ms 44540 KB Output is correct
52 Correct 49 ms 44668 KB Output is correct
53 Correct 48 ms 44668 KB Output is correct
54 Correct 38 ms 44668 KB Output is correct
55 Correct 38 ms 44668 KB Output is correct
56 Correct 57 ms 44852 KB Output is correct
57 Correct 36 ms 44852 KB Output is correct
58 Correct 51 ms 45132 KB Output is correct
59 Correct 53 ms 45132 KB Output is correct
60 Correct 57 ms 45132 KB Output is correct
61 Correct 52 ms 45132 KB Output is correct
62 Correct 88 ms 45132 KB Output is correct
63 Correct 106 ms 45132 KB Output is correct
64 Correct 112 ms 45132 KB Output is correct
65 Correct 185 ms 45132 KB Output is correct
66 Correct 321 ms 45132 KB Output is correct
67 Correct 141 ms 45132 KB Output is correct