답안 #52620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52620 2018-06-26T09:46:13 Z chpipis Jakarta Skyscrapers (APIO15_skyscraper) C++11
57 / 100
1000 ms 35916 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;

int dist[MAXN][SIZE];
priority_queue<pair<int, ii>, vector<pair<int, ii> >, greater<pair<int, ii> > > pq;
vi vec[MAXN];

void relax(int i, int x, int d) {
    if (dist[i][x] <= d) return;
    dist[i][x] = d;
    pq.push(mp(d, mp(i, x)));
}

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 (i == 1) en = b;
    }
    for (int i = 0; i <= n; i++)
        for (int j = 0; j < SIZE; j++)
            dist[i][j] = INF;
    dist[st][0] = 0;
    pq.push(mp(0, mp(st, 0)));
    while (!pq.empty()) {
        int w = pq.top().fi;
        int u = pq.top().se.fi;
        int x = pq.top().se.se;
        pq.pop();

        if (dist[u][x] < w) continue;

        if (x == 0) {
            for (auto it : vec[u]) {
                if (it < SIZE) {
                    relax(u, it, w);
                } else {
                    for (int v = u + it; v < n; v += it) {
                        relax(v, 0, w + (v - u) / it);
                    }
                    for (int v = u - it; v >= 0; v -= it) {
                        relax(v, 0, w + (u - v) / it);
                    }
                }
            }
        } else {
            relax(u, 0, w);
            if (u + x < n)
                relax(u + x, x, w + 1);
            if (u - x >= 0)
                relax(u - x, x, w + 1);
        }
    }
    int ans = *min_element(dist[en], dist[en] + SIZE);
    if (ans == INF)
        puts("-1");
    else
        printf("%d\n", ans);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:75: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:78: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 4 ms 1016 KB Output is correct
2 Correct 4 ms 1172 KB Output is correct
3 Correct 4 ms 1180 KB Output is correct
4 Correct 3 ms 1180 KB Output is correct
5 Correct 3 ms 1292 KB Output is correct
6 Correct 3 ms 1292 KB Output is correct
7 Correct 3 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1428 KB Output is correct
2 Correct 3 ms 1428 KB Output is correct
3 Correct 3 ms 1428 KB Output is correct
4 Correct 3 ms 1540 KB Output is correct
5 Correct 3 ms 1540 KB Output is correct
6 Correct 4 ms 1540 KB Output is correct
7 Correct 4 ms 1540 KB Output is correct
8 Correct 3 ms 1540 KB Output is correct
9 Correct 3 ms 1540 KB Output is correct
10 Correct 3 ms 1568 KB Output is correct
11 Correct 4 ms 1568 KB Output is correct
12 Correct 3 ms 1584 KB Output is correct
13 Correct 4 ms 1612 KB Output is correct
14 Correct 4 ms 1640 KB Output is correct
15 Correct 4 ms 1672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1672 KB Output is correct
2 Correct 3 ms 1672 KB Output is correct
3 Correct 3 ms 1672 KB Output is correct
4 Correct 3 ms 1672 KB Output is correct
5 Correct 3 ms 1672 KB Output is correct
6 Correct 3 ms 1672 KB Output is correct
7 Correct 3 ms 1672 KB Output is correct
8 Correct 3 ms 1672 KB Output is correct
9 Correct 3 ms 1672 KB Output is correct
10 Correct 4 ms 1732 KB Output is correct
11 Correct 6 ms 1860 KB Output is correct
12 Correct 4 ms 1860 KB Output is correct
13 Correct 4 ms 1860 KB Output is correct
14 Correct 6 ms 1860 KB Output is correct
15 Correct 4 ms 1860 KB Output is correct
16 Correct 3 ms 1860 KB Output is correct
17 Correct 6 ms 2316 KB Output is correct
18 Correct 4 ms 2912 KB Output is correct
19 Correct 4 ms 3112 KB Output is correct
20 Correct 4 ms 3120 KB Output is correct
21 Correct 3 ms 3120 KB Output is correct
22 Correct 4 ms 3120 KB Output is correct
23 Correct 5 ms 3120 KB Output is correct
24 Correct 8 ms 3168 KB Output is correct
25 Correct 5 ms 3296 KB Output is correct
26 Correct 5 ms 3296 KB Output is correct
27 Correct 4 ms 3296 KB Output is correct
28 Correct 6 ms 3312 KB Output is correct
29 Correct 11 ms 3312 KB Output is correct
30 Correct 5 ms 3312 KB Output is correct
31 Correct 8 ms 3400 KB Output is correct
32 Correct 7 ms 3400 KB Output is correct
33 Correct 19 ms 3400 KB Output is correct
34 Correct 19 ms 3400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3400 KB Output is correct
2 Correct 2 ms 3400 KB Output is correct
3 Correct 2 ms 3400 KB Output is correct
4 Correct 2 ms 3400 KB Output is correct
5 Correct 3 ms 3400 KB Output is correct
6 Correct 3 ms 3400 KB Output is correct
7 Correct 2 ms 3400 KB Output is correct
8 Correct 2 ms 3400 KB Output is correct
9 Correct 3 ms 3400 KB Output is correct
10 Correct 3 ms 3400 KB Output is correct
11 Correct 4 ms 3400 KB Output is correct
12 Correct 2 ms 3400 KB Output is correct
13 Correct 3 ms 3400 KB Output is correct
14 Correct 4 ms 3400 KB Output is correct
15 Correct 4 ms 3400 KB Output is correct
16 Correct 3 ms 3400 KB Output is correct
17 Correct 5 ms 3400 KB Output is correct
18 Correct 4 ms 3460 KB Output is correct
19 Correct 4 ms 3600 KB Output is correct
20 Correct 4 ms 3600 KB Output is correct
21 Correct 3 ms 3600 KB Output is correct
22 Correct 4 ms 3600 KB Output is correct
23 Correct 5 ms 3600 KB Output is correct
24 Correct 6 ms 3600 KB Output is correct
25 Correct 6 ms 3600 KB Output is correct
26 Correct 6 ms 3612 KB Output is correct
27 Correct 5 ms 3612 KB Output is correct
28 Correct 5 ms 3612 KB Output is correct
29 Correct 11 ms 3624 KB Output is correct
30 Correct 5 ms 3632 KB Output is correct
31 Correct 7 ms 3636 KB Output is correct
32 Correct 7 ms 3716 KB Output is correct
33 Correct 19 ms 3720 KB Output is correct
34 Correct 21 ms 3736 KB Output is correct
35 Correct 24 ms 3804 KB Output is correct
36 Correct 6 ms 3804 KB Output is correct
37 Correct 26 ms 4416 KB Output is correct
38 Correct 26 ms 4732 KB Output is correct
39 Correct 26 ms 4996 KB Output is correct
40 Correct 27 ms 5264 KB Output is correct
41 Correct 26 ms 5604 KB Output is correct
42 Correct 10 ms 5612 KB Output is correct
43 Correct 9 ms 5740 KB Output is correct
44 Correct 13 ms 5932 KB Output is correct
45 Correct 78 ms 6620 KB Output is correct
46 Correct 65 ms 6944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6944 KB Output is correct
2 Correct 3 ms 6944 KB Output is correct
3 Correct 3 ms 6944 KB Output is correct
4 Correct 3 ms 6944 KB Output is correct
5 Correct 3 ms 6944 KB Output is correct
6 Correct 3 ms 6944 KB Output is correct
7 Correct 2 ms 6944 KB Output is correct
8 Correct 2 ms 6944 KB Output is correct
9 Correct 2 ms 6944 KB Output is correct
10 Correct 3 ms 6944 KB Output is correct
11 Correct 4 ms 6944 KB Output is correct
12 Correct 3 ms 6944 KB Output is correct
13 Correct 3 ms 6944 KB Output is correct
14 Correct 4 ms 6944 KB Output is correct
15 Correct 4 ms 6944 KB Output is correct
16 Correct 3 ms 6944 KB Output is correct
17 Correct 6 ms 6944 KB Output is correct
18 Correct 4 ms 6944 KB Output is correct
19 Correct 4 ms 6944 KB Output is correct
20 Correct 4 ms 6944 KB Output is correct
21 Correct 3 ms 6944 KB Output is correct
22 Correct 4 ms 6944 KB Output is correct
23 Correct 4 ms 6944 KB Output is correct
24 Correct 5 ms 6944 KB Output is correct
25 Correct 5 ms 6944 KB Output is correct
26 Correct 5 ms 6944 KB Output is correct
27 Correct 4 ms 6944 KB Output is correct
28 Correct 6 ms 6944 KB Output is correct
29 Correct 13 ms 6944 KB Output is correct
30 Correct 6 ms 6944 KB Output is correct
31 Correct 8 ms 6944 KB Output is correct
32 Correct 7 ms 6944 KB Output is correct
33 Correct 19 ms 6944 KB Output is correct
34 Correct 21 ms 6944 KB Output is correct
35 Correct 19 ms 6944 KB Output is correct
36 Correct 6 ms 6944 KB Output is correct
37 Correct 28 ms 7384 KB Output is correct
38 Correct 26 ms 7756 KB Output is correct
39 Correct 26 ms 7904 KB Output is correct
40 Correct 27 ms 8248 KB Output is correct
41 Correct 27 ms 8380 KB Output is correct
42 Correct 10 ms 8444 KB Output is correct
43 Correct 9 ms 8656 KB Output is correct
44 Correct 11 ms 8860 KB Output is correct
45 Correct 66 ms 9588 KB Output is correct
46 Correct 65 ms 9728 KB Output is correct
47 Correct 112 ms 17236 KB Output is correct
48 Correct 23 ms 24572 KB Output is correct
49 Correct 24 ms 26352 KB Output is correct
50 Correct 34 ms 28024 KB Output is correct
51 Correct 87 ms 30560 KB Output is correct
52 Correct 107 ms 30888 KB Output is correct
53 Correct 41 ms 30888 KB Output is correct
54 Correct 20 ms 30888 KB Output is correct
55 Correct 22 ms 30888 KB Output is correct
56 Correct 31 ms 31380 KB Output is correct
57 Correct 104 ms 31380 KB Output is correct
58 Correct 36 ms 31380 KB Output is correct
59 Correct 35 ms 31380 KB Output is correct
60 Correct 40 ms 31380 KB Output is correct
61 Correct 34 ms 31476 KB Output is correct
62 Correct 67 ms 32492 KB Output is correct
63 Correct 74 ms 33708 KB Output is correct
64 Correct 80 ms 33936 KB Output is correct
65 Correct 470 ms 34160 KB Output is correct
66 Execution timed out 1082 ms 35916 KB Time limit exceeded
67 Halted 0 ms 0 KB -