답안 #46601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46601 2018-04-22T08:22:36 Z tieunhi Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
899 ms 27636 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define N 30005
#define MAGIC 205
#define maxc 1000000007

using namespace std;

int n, m, b[N], p[N];
vector<int> vec[N];
int d[N][MAGIC];

struct state
{
    int l, x, w;
    state(int _l=0, int _x=0, int _w=0) : l(_l), x(_x), w(_w) {}
    bool operator < (const state &rhs) const
    {
        return l > rhs.l;
    }
};
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("INP.TXT", "r", stdin);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> b[i] >> p[i];
        vec[b[i]].PB(p[i]);
    }
    priority_queue<state>q;
    q.push(state(0, b[0], 0));

    memset(d, 60, sizeof d);
    d[b[0]][0] = 0;
    while (!q.empty())
    {
        auto z = q.top(); q.pop();
        int l = z.l;
        int x = z.x;
        int w = z.w;

        if (d[x][w] < l) continue;

        if (x == b[1])
        {
            cout <<l;
            return 0;
        }
        if (w)
        {
            if (d[x][0] > l) {
                d[x][0] = l; q.push(state(l, x, 0));
            }
            if (x + w < n && d[x + w][w] > l + 1) {
                d[x + w][w] = l+1; q.push(state(l+1, x+w, w));
            }
            if (x - w >= 0 && d[x - w][w] > l + 1) {
                d[x - w][w] = l+1; q.push(state(l+1, x-w, w));
            }
        }
        else
        {
            for (auto ww : vec[x])
            {
                if (ww >= MAGIC)
                {
                    for (int y = x % ww; y < n; y += ww)
                        if (d[y][0] > d[x][w] + abs(x - y)/ww)
                        {
                            d[y][0] = d[x][w] + abs(x - y)/ww;
                            q.push(state(d[y][0], y, 0));
                        }
                }
                else
                {
                    if (d[x][ww] > l)
                    {
                        d[x][ww] = l;
                        q.push(state(d[x][ww], x, ww));
                    }
                }
            }
        }
    }
    cout <<-1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 25080 KB Output is correct
2 Correct 20 ms 25208 KB Output is correct
3 Correct 20 ms 25248 KB Output is correct
4 Correct 20 ms 25292 KB Output is correct
5 Correct 20 ms 25292 KB Output is correct
6 Correct 20 ms 25292 KB Output is correct
7 Correct 22 ms 25468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 25468 KB Output is correct
2 Correct 19 ms 25468 KB Output is correct
3 Correct 20 ms 25468 KB Output is correct
4 Correct 20 ms 25468 KB Output is correct
5 Correct 20 ms 25468 KB Output is correct
6 Correct 20 ms 25468 KB Output is correct
7 Correct 20 ms 25468 KB Output is correct
8 Correct 20 ms 25468 KB Output is correct
9 Correct 20 ms 25468 KB Output is correct
10 Correct 23 ms 25468 KB Output is correct
11 Correct 21 ms 25468 KB Output is correct
12 Correct 21 ms 25468 KB Output is correct
13 Correct 23 ms 25468 KB Output is correct
14 Correct 21 ms 25468 KB Output is correct
15 Correct 24 ms 25468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 25468 KB Output is correct
2 Correct 20 ms 25468 KB Output is correct
3 Correct 20 ms 25468 KB Output is correct
4 Correct 20 ms 25468 KB Output is correct
5 Correct 20 ms 25468 KB Output is correct
6 Correct 20 ms 25468 KB Output is correct
7 Correct 21 ms 25468 KB Output is correct
8 Correct 20 ms 25468 KB Output is correct
9 Correct 20 ms 25468 KB Output is correct
10 Correct 20 ms 25468 KB Output is correct
11 Correct 20 ms 25468 KB Output is correct
12 Correct 20 ms 25468 KB Output is correct
13 Correct 22 ms 25468 KB Output is correct
14 Correct 21 ms 25468 KB Output is correct
15 Correct 24 ms 25468 KB Output is correct
16 Correct 21 ms 25468 KB Output is correct
17 Correct 22 ms 25468 KB Output is correct
18 Correct 20 ms 25468 KB Output is correct
19 Correct 20 ms 25468 KB Output is correct
20 Correct 21 ms 25468 KB Output is correct
21 Correct 20 ms 25468 KB Output is correct
22 Correct 20 ms 25468 KB Output is correct
23 Correct 21 ms 25468 KB Output is correct
24 Correct 25 ms 25468 KB Output is correct
25 Correct 22 ms 25468 KB Output is correct
26 Correct 24 ms 25468 KB Output is correct
27 Correct 21 ms 25468 KB Output is correct
28 Correct 24 ms 25468 KB Output is correct
29 Correct 29 ms 25468 KB Output is correct
30 Correct 26 ms 25468 KB Output is correct
31 Correct 23 ms 25468 KB Output is correct
32 Correct 22 ms 25468 KB Output is correct
33 Correct 30 ms 25468 KB Output is correct
34 Correct 26 ms 25468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 25468 KB Output is correct
2 Correct 20 ms 25468 KB Output is correct
3 Correct 21 ms 25468 KB Output is correct
4 Correct 21 ms 25468 KB Output is correct
5 Correct 22 ms 25468 KB Output is correct
6 Correct 20 ms 25468 KB Output is correct
7 Correct 20 ms 25468 KB Output is correct
8 Correct 20 ms 25468 KB Output is correct
9 Correct 20 ms 25468 KB Output is correct
10 Correct 21 ms 25468 KB Output is correct
11 Correct 20 ms 25468 KB Output is correct
12 Correct 21 ms 25468 KB Output is correct
13 Correct 21 ms 25468 KB Output is correct
14 Correct 21 ms 25468 KB Output is correct
15 Correct 21 ms 25468 KB Output is correct
16 Correct 20 ms 25468 KB Output is correct
17 Correct 22 ms 25468 KB Output is correct
18 Correct 21 ms 25468 KB Output is correct
19 Correct 24 ms 25468 KB Output is correct
20 Correct 25 ms 25468 KB Output is correct
21 Correct 21 ms 25468 KB Output is correct
22 Correct 21 ms 25468 KB Output is correct
23 Correct 22 ms 25468 KB Output is correct
24 Correct 23 ms 25468 KB Output is correct
25 Correct 23 ms 25468 KB Output is correct
26 Correct 21 ms 25468 KB Output is correct
27 Correct 23 ms 25468 KB Output is correct
28 Correct 24 ms 25592 KB Output is correct
29 Correct 25 ms 25592 KB Output is correct
30 Correct 26 ms 25592 KB Output is correct
31 Correct 23 ms 25592 KB Output is correct
32 Correct 22 ms 25592 KB Output is correct
33 Correct 30 ms 25592 KB Output is correct
34 Correct 26 ms 25592 KB Output is correct
35 Correct 29 ms 25980 KB Output is correct
36 Correct 23 ms 25980 KB Output is correct
37 Correct 26 ms 25980 KB Output is correct
38 Correct 28 ms 25980 KB Output is correct
39 Correct 28 ms 25980 KB Output is correct
40 Correct 27 ms 25980 KB Output is correct
41 Correct 32 ms 25980 KB Output is correct
42 Correct 26 ms 25980 KB Output is correct
43 Correct 25 ms 25980 KB Output is correct
44 Correct 26 ms 25980 KB Output is correct
45 Correct 66 ms 26304 KB Output is correct
46 Correct 44 ms 26304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 26304 KB Output is correct
2 Correct 20 ms 26304 KB Output is correct
3 Correct 21 ms 26304 KB Output is correct
4 Correct 22 ms 26304 KB Output is correct
5 Correct 24 ms 26304 KB Output is correct
6 Correct 23 ms 26304 KB Output is correct
7 Correct 21 ms 26304 KB Output is correct
8 Correct 20 ms 26304 KB Output is correct
9 Correct 20 ms 26304 KB Output is correct
10 Correct 21 ms 26304 KB Output is correct
11 Correct 20 ms 26304 KB Output is correct
12 Correct 20 ms 26304 KB Output is correct
13 Correct 20 ms 26304 KB Output is correct
14 Correct 21 ms 26304 KB Output is correct
15 Correct 21 ms 26304 KB Output is correct
16 Correct 21 ms 26304 KB Output is correct
17 Correct 22 ms 26304 KB Output is correct
18 Correct 21 ms 26304 KB Output is correct
19 Correct 23 ms 26304 KB Output is correct
20 Correct 21 ms 26304 KB Output is correct
21 Correct 21 ms 26304 KB Output is correct
22 Correct 21 ms 26304 KB Output is correct
23 Correct 21 ms 26304 KB Output is correct
24 Correct 21 ms 26304 KB Output is correct
25 Correct 22 ms 26304 KB Output is correct
26 Correct 22 ms 26304 KB Output is correct
27 Correct 21 ms 26304 KB Output is correct
28 Correct 27 ms 26304 KB Output is correct
29 Correct 32 ms 26304 KB Output is correct
30 Correct 22 ms 26304 KB Output is correct
31 Correct 23 ms 26304 KB Output is correct
32 Correct 24 ms 26304 KB Output is correct
33 Correct 30 ms 26304 KB Output is correct
34 Correct 27 ms 26304 KB Output is correct
35 Correct 32 ms 26304 KB Output is correct
36 Correct 24 ms 26304 KB Output is correct
37 Correct 26 ms 26304 KB Output is correct
38 Correct 30 ms 26304 KB Output is correct
39 Correct 27 ms 26304 KB Output is correct
40 Correct 28 ms 26304 KB Output is correct
41 Correct 28 ms 26304 KB Output is correct
42 Correct 25 ms 26304 KB Output is correct
43 Correct 25 ms 26304 KB Output is correct
44 Correct 25 ms 26304 KB Output is correct
45 Correct 70 ms 26304 KB Output is correct
46 Correct 46 ms 26356 KB Output is correct
47 Correct 32 ms 26428 KB Output is correct
48 Correct 28 ms 26428 KB Output is correct
49 Correct 27 ms 26428 KB Output is correct
50 Correct 26 ms 26428 KB Output is correct
51 Correct 41 ms 26684 KB Output is correct
52 Correct 43 ms 26684 KB Output is correct
53 Correct 32 ms 26684 KB Output is correct
54 Correct 21 ms 26684 KB Output is correct
55 Correct 26 ms 26684 KB Output is correct
56 Correct 35 ms 26684 KB Output is correct
57 Correct 23 ms 26684 KB Output is correct
58 Correct 31 ms 26684 KB Output is correct
59 Correct 31 ms 26684 KB Output is correct
60 Correct 31 ms 26684 KB Output is correct
61 Correct 29 ms 26684 KB Output is correct
62 Correct 73 ms 26684 KB Output is correct
63 Correct 68 ms 27448 KB Output is correct
64 Correct 75 ms 27508 KB Output is correct
65 Correct 443 ms 27508 KB Output is correct
66 Correct 899 ms 27508 KB Output is correct
67 Correct 402 ms 27636 KB Output is correct