Submission #52731

# Submission time Handle Problem Language Result Execution time Memory
52731 2018-06-26T13:23:14 Z chpipis Jakarta Skyscrapers (APIO15_skyscraper) C++11
100 / 100
137 ms 17628 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int SIZE = 175;
const int MAXN = 3e4 + 5;
const int INF = 1e9;

bool dist[MAXN][SIZE];
deque<pair<int, ii> > deq;
bool visit[MAXN];
vi vec[MAXN];

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int n, m, st = -1, en = -1;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int b, p;
        scanf("%d %d", &b, &p);
        vec[b].pb(p);
        if (i == 0) {
            st = b;
            if (p < SIZE) {
                dist[st][p] = true;
            } else {
                deq.pb(mp(0, mp(st, -p)));
            }
            deq.pb(mp(0, mp(st, p)));
        }
        if (i == 1) en = b;
    }
    //memset(dist, false, sizeof dist);
    /*
    for (int i = 0; i <= n; i++)
        for (int j = 0; j < SIZE; j++)
            dist[i][j] = INF;
    */
    int ans = -1;
    while (!deq.empty()) {
        int w = deq.front().fi;
        int u = deq.front().se.fi;
        int x = deq.front().se.se;
        deq.pop_front();

        if (u == en) {
            ans = w;
            break;
        }

        if (x < 0 || x >= SIZE) {
            if (0 <= u + x && u + x < n) {
                deq.pb(mp(w + 1, mp(u + x, x)));
            }
        } else {
            if (u - x >= 0 && !dist[u - x][x]) {
                dist[u - x][x] = true;
                deq.pb(mp(w + 1, mp(u - x, x)));
            }
            if (u + x < n && !dist[u + x][x]) {
                dist[u + x][x] = true;
                deq.pb(mp(w + 1, mp(u + x, x)));
            }
        }

        if (visit[u]) continue;
        visit[u] = true;

        for (auto it : vec[u]) {
            if (it < SIZE) {
                if (!dist[u][it]) {
                    dist[u][it] = true;
                    deq.pf(mp(w, mp(u, it)));
                }
            } else {
                deq.pf(mp(w, mp(u, it)));
                deq.pf(mp(w, mp(u, -it)));
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:70: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:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &b, &p);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 2 ms 1164 KB Output is correct
3 Correct 2 ms 1176 KB Output is correct
4 Correct 3 ms 1252 KB Output is correct
5 Correct 3 ms 1252 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 3 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1272 KB Output is correct
2 Correct 3 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 3 ms 1272 KB Output is correct
5 Correct 3 ms 1384 KB Output is correct
6 Correct 3 ms 1384 KB Output is correct
7 Correct 2 ms 1384 KB Output is correct
8 Correct 3 ms 1484 KB Output is correct
9 Correct 3 ms 1484 KB Output is correct
10 Correct 3 ms 1484 KB Output is correct
11 Correct 3 ms 1484 KB Output is correct
12 Correct 3 ms 1484 KB Output is correct
13 Correct 3 ms 1552 KB Output is correct
14 Correct 4 ms 1580 KB Output is correct
15 Correct 3 ms 1608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1608 KB Output is correct
2 Correct 3 ms 1608 KB Output is correct
3 Correct 3 ms 1608 KB Output is correct
4 Correct 2 ms 1608 KB Output is correct
5 Correct 3 ms 1608 KB Output is correct
6 Correct 3 ms 1608 KB Output is correct
7 Correct 2 ms 1648 KB Output is correct
8 Correct 2 ms 1648 KB Output is correct
9 Correct 3 ms 1696 KB Output is correct
10 Correct 3 ms 1696 KB Output is correct
11 Correct 5 ms 1720 KB Output is correct
12 Correct 3 ms 1732 KB Output is correct
13 Correct 5 ms 1732 KB Output is correct
14 Correct 4 ms 1772 KB Output is correct
15 Correct 3 ms 1784 KB Output is correct
16 Correct 4 ms 1784 KB Output is correct
17 Correct 5 ms 1808 KB Output is correct
18 Correct 4 ms 1808 KB Output is correct
19 Correct 3 ms 1808 KB Output is correct
20 Correct 4 ms 2096 KB Output is correct
21 Correct 3 ms 2096 KB Output is correct
22 Correct 3 ms 2096 KB Output is correct
23 Correct 4 ms 2132 KB Output is correct
24 Correct 4 ms 2144 KB Output is correct
25 Correct 4 ms 2144 KB Output is correct
26 Correct 4 ms 2184 KB Output is correct
27 Correct 3 ms 2328 KB Output is correct
28 Correct 4 ms 2328 KB Output is correct
29 Correct 5 ms 2328 KB Output is correct
30 Correct 4 ms 2328 KB Output is correct
31 Correct 4 ms 2328 KB Output is correct
32 Correct 4 ms 2328 KB Output is correct
33 Correct 5 ms 2328 KB Output is correct
34 Correct 4 ms 2328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2328 KB Output is correct
2 Correct 3 ms 2328 KB Output is correct
3 Correct 3 ms 2328 KB Output is correct
4 Correct 2 ms 2328 KB Output is correct
5 Correct 3 ms 2328 KB Output is correct
6 Correct 3 ms 2328 KB Output is correct
7 Correct 3 ms 2328 KB Output is correct
8 Correct 2 ms 2328 KB Output is correct
9 Correct 3 ms 2328 KB Output is correct
10 Correct 3 ms 2328 KB Output is correct
11 Correct 4 ms 2328 KB Output is correct
12 Correct 3 ms 2328 KB Output is correct
13 Correct 3 ms 2328 KB Output is correct
14 Correct 3 ms 2328 KB Output is correct
15 Correct 3 ms 2328 KB Output is correct
16 Correct 3 ms 2328 KB Output is correct
17 Correct 4 ms 2328 KB Output is correct
18 Correct 3 ms 2328 KB Output is correct
19 Correct 3 ms 2328 KB Output is correct
20 Correct 3 ms 2428 KB Output is correct
21 Correct 2 ms 2428 KB Output is correct
22 Correct 3 ms 2428 KB Output is correct
23 Correct 3 ms 2464 KB Output is correct
24 Correct 4 ms 2476 KB Output is correct
25 Correct 3 ms 2476 KB Output is correct
26 Correct 4 ms 2516 KB Output is correct
27 Correct 3 ms 2564 KB Output is correct
28 Correct 4 ms 2580 KB Output is correct
29 Correct 5 ms 2600 KB Output is correct
30 Correct 3 ms 2612 KB Output is correct
31 Correct 3 ms 2616 KB Output is correct
32 Correct 3 ms 2620 KB Output is correct
33 Correct 5 ms 2624 KB Output is correct
34 Correct 4 ms 2636 KB Output is correct
35 Correct 14 ms 3160 KB Output is correct
36 Correct 4 ms 3160 KB Output is correct
37 Correct 10 ms 3380 KB Output is correct
38 Correct 12 ms 3708 KB Output is correct
39 Correct 11 ms 3708 KB Output is correct
40 Correct 12 ms 4108 KB Output is correct
41 Correct 20 ms 4456 KB Output is correct
42 Correct 9 ms 4508 KB Output is correct
43 Correct 9 ms 4716 KB Output is correct
44 Correct 8 ms 4928 KB Output is correct
45 Correct 17 ms 5520 KB Output is correct
46 Correct 14 ms 5604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5604 KB Output is correct
2 Correct 3 ms 5604 KB Output is correct
3 Correct 2 ms 5604 KB Output is correct
4 Correct 3 ms 5604 KB Output is correct
5 Correct 2 ms 5604 KB Output is correct
6 Correct 2 ms 5604 KB Output is correct
7 Correct 3 ms 5604 KB Output is correct
8 Correct 3 ms 5604 KB Output is correct
9 Correct 3 ms 5604 KB Output is correct
10 Correct 3 ms 5604 KB Output is correct
11 Correct 3 ms 5604 KB Output is correct
12 Correct 3 ms 5604 KB Output is correct
13 Correct 3 ms 5604 KB Output is correct
14 Correct 3 ms 5604 KB Output is correct
15 Correct 3 ms 5604 KB Output is correct
16 Correct 3 ms 5604 KB Output is correct
17 Correct 4 ms 5604 KB Output is correct
18 Correct 3 ms 5604 KB Output is correct
19 Correct 3 ms 5604 KB Output is correct
20 Correct 4 ms 5604 KB Output is correct
21 Correct 3 ms 5604 KB Output is correct
22 Correct 2 ms 5604 KB Output is correct
23 Correct 4 ms 5604 KB Output is correct
24 Correct 4 ms 5604 KB Output is correct
25 Correct 4 ms 5604 KB Output is correct
26 Correct 4 ms 5604 KB Output is correct
27 Correct 5 ms 5604 KB Output is correct
28 Correct 5 ms 5604 KB Output is correct
29 Correct 4 ms 5604 KB Output is correct
30 Correct 4 ms 5604 KB Output is correct
31 Correct 5 ms 5604 KB Output is correct
32 Correct 5 ms 5604 KB Output is correct
33 Correct 6 ms 5604 KB Output is correct
34 Correct 5 ms 5604 KB Output is correct
35 Correct 12 ms 6052 KB Output is correct
36 Correct 4 ms 6052 KB Output is correct
37 Correct 10 ms 6392 KB Output is correct
38 Correct 13 ms 6600 KB Output is correct
39 Correct 12 ms 6600 KB Output is correct
40 Correct 13 ms 7052 KB Output is correct
41 Correct 12 ms 7424 KB Output is correct
42 Correct 8 ms 7672 KB Output is correct
43 Correct 10 ms 7692 KB Output is correct
44 Correct 9 ms 7900 KB Output is correct
45 Correct 19 ms 8492 KB Output is correct
46 Correct 14 ms 8580 KB Output is correct
47 Correct 14 ms 10580 KB Output is correct
48 Correct 11 ms 10580 KB Output is correct
49 Correct 13 ms 10580 KB Output is correct
50 Correct 9 ms 10580 KB Output is correct
51 Correct 22 ms 12476 KB Output is correct
52 Correct 22 ms 13208 KB Output is correct
53 Correct 15 ms 13208 KB Output is correct
54 Correct 8 ms 14796 KB Output is correct
55 Correct 8 ms 14996 KB Output is correct
56 Correct 20 ms 15960 KB Output is correct
57 Correct 4 ms 15960 KB Output is correct
58 Correct 20 ms 15960 KB Output is correct
59 Correct 16 ms 15960 KB Output is correct
60 Correct 20 ms 15960 KB Output is correct
61 Correct 16 ms 16212 KB Output is correct
62 Correct 33 ms 17148 KB Output is correct
63 Correct 49 ms 17148 KB Output is correct
64 Correct 47 ms 17148 KB Output is correct
65 Correct 77 ms 17420 KB Output is correct
66 Correct 137 ms 17628 KB Output is correct
67 Correct 78 ms 17628 KB Output is correct