답안 #239246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
239246 2020-06-15T00:47:57 Z ant101 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
396 ms 262148 KB
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

typedef long long ll;


ll add(ll a, ll b) {
    a += b;
    if(a >= MOD) {
        a -= MOD;
    }
    return a;
}
ll sub(ll a, ll b) {
    a -= b;
    if(a < 0) {
        a += MOD;
    }
    return a;
}

ll mul(ll a, ll b) {
    return (a * b)%MOD;
}

void add_self(ll& a, ll b) {
    a = add(a, b);
}
void sub_self(ll& a, ll b) {
    a = sub(a, b);
}
void mul_self(ll& a, ll b) {
    a = mul(a, b);
}


const ll MAXN = 30010;

ll sp[MAXN][175];
ll N, M;
pair<ll, ll> doge[MAXN];
vector<pair<pair<ll, ll>, ll>> adj[MAXN][175];

void dij(ll start) {
    for (ll i = 0; i<N; i++) {
        for (ll j = 0; j<=sqrt(N); j++) {
            sp[i][j] = 1e13;
        }
    }
    priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> pq;
    pq.push({0, {doge[start].first, 0}});
    sp[doge[start].first][0] = 0;
    while (pq.size() != 0) {
        ll d = pq.top().first, u = pq.top().second.first, p = pq.top().second.second;
        pq.pop();
        if (sp[u][p] != d) {
            continue;
        }
        if (p != 0) {
            if (u-p >= 0) {
                adj[u][p].push_back({{u-p, p}, 1});
            }
            if (u+p < N) {
                adj[u][p].push_back({{u+p, p}, 1});
            }
            adj[u][p].push_back({{u, 0}, 0});
        }
        for (auto edge : adj[u][p]) {
            ll v = edge.first.first, np = edge.first.second, w = edge.second;
            if (d+w < sp[v][np]) {
                sp[v][np] = d+w;
                pq.push({d+w, {v, np}});
            }
        }
        if (p != 0) {
            if (u-p >= 0) {
                adj[u][p].pop_back();
            }
            if (u+p < N) {
                adj[u][p].pop_back();
            }
            adj[u][p].push_back({{u, 0}, 0});
        }
    }
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M;
    for (ll i = 0; i<M; i++) {
        ll a, b;
        cin >> a >> b;
        doge[i] = {a, b};
        if (b<=sqrt(N)) {
            adj[a][0].push_back({{a, b}, 0});
        } else {
            for (ll j = 1; j<=N; j++) {
                ll hold = 0;
                if (a-b*j >= 0) {
                    hold++;
                    adj[a][0].push_back({{a-b*j, 0}, j});
                }
                if (a+b*j < N) {
                    hold++;
                    adj[a][0].push_back({{a+b*j, 0}, j});
                }
                if (!hold) {
                    break;
                }
            }
        }
    }
    dij(0);
    cout << (sp[doge[1].first][0] == 1e13 ? -1 : sp[doge[1].first][0]) << "\n";
    return 0;
}




# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 123640 KB Output is correct
2 Correct 74 ms 123640 KB Output is correct
3 Correct 77 ms 123640 KB Output is correct
4 Correct 76 ms 123640 KB Output is correct
5 Correct 86 ms 123724 KB Output is correct
6 Correct 77 ms 123640 KB Output is correct
7 Correct 76 ms 123640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 123660 KB Output is correct
2 Correct 77 ms 123640 KB Output is correct
3 Correct 76 ms 123640 KB Output is correct
4 Correct 76 ms 123640 KB Output is correct
5 Correct 77 ms 123660 KB Output is correct
6 Correct 77 ms 123676 KB Output is correct
7 Correct 78 ms 123640 KB Output is correct
8 Correct 75 ms 123768 KB Output is correct
9 Correct 74 ms 123640 KB Output is correct
10 Correct 75 ms 123896 KB Output is correct
11 Correct 75 ms 124024 KB Output is correct
12 Correct 77 ms 123896 KB Output is correct
13 Correct 79 ms 124024 KB Output is correct
14 Correct 76 ms 124024 KB Output is correct
15 Correct 77 ms 124032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 123640 KB Output is correct
2 Correct 76 ms 123744 KB Output is correct
3 Correct 80 ms 123768 KB Output is correct
4 Correct 88 ms 123640 KB Output is correct
5 Correct 77 ms 123640 KB Output is correct
6 Correct 77 ms 123768 KB Output is correct
7 Correct 77 ms 123768 KB Output is correct
8 Correct 75 ms 123880 KB Output is correct
9 Correct 77 ms 123768 KB Output is correct
10 Correct 91 ms 123896 KB Output is correct
11 Correct 77 ms 124024 KB Output is correct
12 Correct 76 ms 124024 KB Output is correct
13 Correct 86 ms 124024 KB Output is correct
14 Correct 75 ms 124076 KB Output is correct
15 Correct 76 ms 124024 KB Output is correct
16 Correct 76 ms 124024 KB Output is correct
17 Correct 81 ms 125688 KB Output is correct
18 Correct 77 ms 126200 KB Output is correct
19 Correct 80 ms 126456 KB Output is correct
20 Correct 81 ms 126712 KB Output is correct
21 Correct 76 ms 124280 KB Output is correct
22 Correct 77 ms 126200 KB Output is correct
23 Correct 79 ms 126328 KB Output is correct
24 Correct 84 ms 127096 KB Output is correct
25 Correct 80 ms 126968 KB Output is correct
26 Correct 79 ms 127228 KB Output is correct
27 Correct 80 ms 127096 KB Output is correct
28 Correct 83 ms 128120 KB Output is correct
29 Correct 102 ms 133112 KB Output is correct
30 Correct 85 ms 128248 KB Output is correct
31 Correct 106 ms 129912 KB Output is correct
32 Correct 99 ms 127992 KB Output is correct
33 Correct 113 ms 136528 KB Output is correct
34 Correct 113 ms 136656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 123640 KB Output is correct
2 Correct 75 ms 123640 KB Output is correct
3 Correct 77 ms 123768 KB Output is correct
4 Correct 76 ms 123768 KB Output is correct
5 Correct 78 ms 123644 KB Output is correct
6 Correct 76 ms 123644 KB Output is correct
7 Correct 77 ms 123896 KB Output is correct
8 Correct 86 ms 123768 KB Output is correct
9 Correct 76 ms 123768 KB Output is correct
10 Correct 77 ms 123864 KB Output is correct
11 Correct 78 ms 124028 KB Output is correct
12 Correct 75 ms 123896 KB Output is correct
13 Correct 75 ms 124064 KB Output is correct
14 Correct 79 ms 124024 KB Output is correct
15 Correct 77 ms 124024 KB Output is correct
16 Correct 76 ms 124024 KB Output is correct
17 Correct 79 ms 125688 KB Output is correct
18 Correct 76 ms 126200 KB Output is correct
19 Correct 78 ms 126456 KB Output is correct
20 Correct 81 ms 126712 KB Output is correct
21 Correct 75 ms 124280 KB Output is correct
22 Correct 76 ms 126200 KB Output is correct
23 Correct 79 ms 126328 KB Output is correct
24 Correct 81 ms 127096 KB Output is correct
25 Correct 82 ms 126968 KB Output is correct
26 Correct 93 ms 127224 KB Output is correct
27 Correct 79 ms 127096 KB Output is correct
28 Correct 82 ms 128224 KB Output is correct
29 Correct 100 ms 133116 KB Output is correct
30 Correct 83 ms 128376 KB Output is correct
31 Correct 107 ms 129912 KB Output is correct
32 Correct 85 ms 127992 KB Output is correct
33 Correct 115 ms 136656 KB Output is correct
34 Correct 118 ms 136656 KB Output is correct
35 Correct 98 ms 131320 KB Output is correct
36 Correct 84 ms 126200 KB Output is correct
37 Correct 113 ms 136568 KB Output is correct
38 Correct 117 ms 135544 KB Output is correct
39 Correct 115 ms 135544 KB Output is correct
40 Correct 122 ms 135460 KB Output is correct
41 Correct 114 ms 135416 KB Output is correct
42 Correct 99 ms 128632 KB Output is correct
43 Correct 97 ms 128372 KB Output is correct
44 Correct 85 ms 127992 KB Output is correct
45 Correct 129 ms 146680 KB Output is correct
46 Correct 141 ms 146680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 123720 KB Output is correct
2 Correct 76 ms 123640 KB Output is correct
3 Correct 76 ms 123640 KB Output is correct
4 Correct 76 ms 123640 KB Output is correct
5 Correct 76 ms 123640 KB Output is correct
6 Correct 75 ms 123768 KB Output is correct
7 Correct 78 ms 123644 KB Output is correct
8 Correct 76 ms 123772 KB Output is correct
9 Correct 75 ms 123768 KB Output is correct
10 Correct 76 ms 123896 KB Output is correct
11 Correct 75 ms 124024 KB Output is correct
12 Correct 76 ms 123896 KB Output is correct
13 Correct 78 ms 123896 KB Output is correct
14 Correct 75 ms 123992 KB Output is correct
15 Correct 88 ms 124024 KB Output is correct
16 Correct 91 ms 124024 KB Output is correct
17 Correct 79 ms 125688 KB Output is correct
18 Correct 83 ms 126232 KB Output is correct
19 Correct 77 ms 126456 KB Output is correct
20 Correct 78 ms 126840 KB Output is correct
21 Correct 77 ms 124280 KB Output is correct
22 Correct 80 ms 126200 KB Output is correct
23 Correct 79 ms 126328 KB Output is correct
24 Correct 95 ms 127096 KB Output is correct
25 Correct 97 ms 126968 KB Output is correct
26 Correct 79 ms 127224 KB Output is correct
27 Correct 79 ms 127096 KB Output is correct
28 Correct 84 ms 128120 KB Output is correct
29 Correct 102 ms 133112 KB Output is correct
30 Correct 84 ms 128352 KB Output is correct
31 Correct 98 ms 129912 KB Output is correct
32 Correct 82 ms 127992 KB Output is correct
33 Correct 139 ms 136524 KB Output is correct
34 Correct 115 ms 136712 KB Output is correct
35 Correct 102 ms 131320 KB Output is correct
36 Correct 83 ms 126200 KB Output is correct
37 Correct 134 ms 136568 KB Output is correct
38 Correct 114 ms 135468 KB Output is correct
39 Correct 116 ms 135620 KB Output is correct
40 Correct 116 ms 135544 KB Output is correct
41 Correct 114 ms 135416 KB Output is correct
42 Correct 88 ms 128500 KB Output is correct
43 Correct 86 ms 128372 KB Output is correct
44 Correct 87 ms 127992 KB Output is correct
45 Correct 133 ms 146808 KB Output is correct
46 Correct 128 ms 146680 KB Output is correct
47 Correct 360 ms 192884 KB Output is correct
48 Correct 132 ms 159224 KB Output is correct
49 Correct 132 ms 161528 KB Output is correct
50 Correct 136 ms 164344 KB Output is correct
51 Correct 272 ms 187980 KB Output is correct
52 Correct 283 ms 190884 KB Output is correct
53 Correct 168 ms 171896 KB Output is correct
54 Correct 143 ms 166368 KB Output is correct
55 Correct 147 ms 167544 KB Output is correct
56 Correct 162 ms 169720 KB Output is correct
57 Correct 396 ms 212324 KB Output is correct
58 Correct 172 ms 173420 KB Output is correct
59 Correct 181 ms 176756 KB Output is correct
60 Correct 202 ms 179408 KB Output is correct
61 Correct 187 ms 176368 KB Output is correct
62 Correct 290 ms 201848 KB Output is correct
63 Correct 265 ms 236460 KB Output is correct
64 Correct 288 ms 248300 KB Output is correct
65 Runtime error 375 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
66 Halted 0 ms 0 KB -