Submission #98070

# Submission time Handle Problem Language Result Execution time Memory
98070 2019-02-20T13:11:15 Z Smelskiy Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
244 ms 65508 KB
#include <bits/stdc++.h>

/*
 unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
 mt19937 g1.seed(seed1);
 
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 */
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pill;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;

int dp[30001];
set<int> amts[30001];
int src, dest;
int n;

vector<pii> edges[30001];

void solve() {
    priority_queue<pii> q;
    q.push(pii(0, src));
    while(!q.empty()) {
        pii curr = q.top();
        q.pop();
        if(curr.second == dest) {
            printf("%d\n", dp[curr.second]);
            return;
        }
        if(dp[curr.second] != -curr.first) continue;
        for(pii out: edges[curr.second]) {
            int nd = out.first;
            int nw = dp[curr.second] + out.second;
            if(nw < dp[nd]) {
                dp[nd] = nw;
                q.push(pii(-dp[nd], nd));
            }
        }
    }
    printf("-1\n");
}

void loadGraph() {
    for(int i = 0; i < n; i++) {
        for(int out: amts[i]) {
            for(int dx = 1; i - dx * out >= 0; dx++) {
                edges[i].push_back(pii(i-dx*out, dx));
                if(amts[i-dx*out].count(out)) break;
            }
            for(int dx = 1; i + dx * out < n; dx++) {
                edges[i].push_back(pii(i+dx*out, dx));
                if(amts[i+dx*out].count(out)) break;
            }
        }
    }
}

int main() {
    int m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++) {
        dp[i] = 1 << 25;
    }
    for(int i = 0; i < m; i++) {
        int loc, jump;
        scanf("%d %d", &loc, &jump);
        amts[loc].insert(jump);
        if(i == 0) {
            src = loc;
            dp[loc] = 0;
        }
        else if(i == 1) {
            dest = loc;
        }
    }
    loadGraph();
    solve();
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:69: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:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &loc, &jump);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2432 KB Output is correct
2 Correct 4 ms 2432 KB Output is correct
3 Correct 5 ms 2432 KB Output is correct
4 Correct 3 ms 2432 KB Output is correct
5 Correct 4 ms 2432 KB Output is correct
6 Correct 4 ms 2432 KB Output is correct
7 Correct 4 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2432 KB Output is correct
2 Correct 5 ms 2432 KB Output is correct
3 Correct 4 ms 2432 KB Output is correct
4 Correct 3 ms 2432 KB Output is correct
5 Correct 5 ms 2432 KB Output is correct
6 Correct 4 ms 2432 KB Output is correct
7 Correct 4 ms 2432 KB Output is correct
8 Correct 4 ms 2432 KB Output is correct
9 Correct 4 ms 2432 KB Output is correct
10 Correct 5 ms 2560 KB Output is correct
11 Correct 5 ms 2560 KB Output is correct
12 Correct 5 ms 2432 KB Output is correct
13 Correct 4 ms 2432 KB Output is correct
14 Correct 5 ms 2560 KB Output is correct
15 Correct 5 ms 2560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2432 KB Output is correct
2 Correct 4 ms 2432 KB Output is correct
3 Correct 5 ms 2432 KB Output is correct
4 Correct 4 ms 2432 KB Output is correct
5 Correct 4 ms 2432 KB Output is correct
6 Correct 5 ms 2432 KB Output is correct
7 Correct 4 ms 2432 KB Output is correct
8 Correct 4 ms 2432 KB Output is correct
9 Correct 5 ms 2432 KB Output is correct
10 Correct 4 ms 2560 KB Output is correct
11 Correct 5 ms 2560 KB Output is correct
12 Correct 5 ms 2432 KB Output is correct
13 Correct 5 ms 2432 KB Output is correct
14 Correct 5 ms 2560 KB Output is correct
15 Correct 5 ms 2560 KB Output is correct
16 Correct 4 ms 2560 KB Output is correct
17 Correct 6 ms 2688 KB Output is correct
18 Correct 5 ms 2560 KB Output is correct
19 Correct 4 ms 2560 KB Output is correct
20 Correct 5 ms 2560 KB Output is correct
21 Correct 5 ms 2560 KB Output is correct
22 Correct 5 ms 2560 KB Output is correct
23 Correct 5 ms 2560 KB Output is correct
24 Correct 7 ms 2688 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 6 ms 2560 KB Output is correct
27 Correct 5 ms 2560 KB Output is correct
28 Correct 5 ms 2816 KB Output is correct
29 Correct 8 ms 3200 KB Output is correct
30 Correct 6 ms 2688 KB Output is correct
31 Correct 5 ms 2944 KB Output is correct
32 Correct 5 ms 2816 KB Output is correct
33 Correct 10 ms 3840 KB Output is correct
34 Correct 9 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2432 KB Output is correct
2 Correct 4 ms 2432 KB Output is correct
3 Correct 4 ms 2432 KB Output is correct
4 Correct 4 ms 2432 KB Output is correct
5 Correct 4 ms 2432 KB Output is correct
6 Correct 5 ms 2432 KB Output is correct
7 Correct 4 ms 2432 KB Output is correct
8 Correct 4 ms 2432 KB Output is correct
9 Correct 5 ms 2432 KB Output is correct
10 Correct 4 ms 2432 KB Output is correct
11 Correct 7 ms 2560 KB Output is correct
12 Correct 4 ms 2432 KB Output is correct
13 Correct 6 ms 2432 KB Output is correct
14 Correct 5 ms 2560 KB Output is correct
15 Correct 6 ms 2688 KB Output is correct
16 Correct 5 ms 2560 KB Output is correct
17 Correct 6 ms 2688 KB Output is correct
18 Correct 5 ms 2560 KB Output is correct
19 Correct 6 ms 2560 KB Output is correct
20 Correct 5 ms 2560 KB Output is correct
21 Correct 5 ms 2560 KB Output is correct
22 Correct 6 ms 2560 KB Output is correct
23 Correct 6 ms 2560 KB Output is correct
24 Correct 6 ms 2688 KB Output is correct
25 Correct 5 ms 2560 KB Output is correct
26 Correct 5 ms 2560 KB Output is correct
27 Correct 6 ms 2560 KB Output is correct
28 Correct 5 ms 2816 KB Output is correct
29 Correct 7 ms 3200 KB Output is correct
30 Correct 6 ms 2816 KB Output is correct
31 Correct 5 ms 2944 KB Output is correct
32 Correct 6 ms 2816 KB Output is correct
33 Correct 10 ms 3840 KB Output is correct
34 Correct 10 ms 3840 KB Output is correct
35 Correct 22 ms 4736 KB Output is correct
36 Correct 7 ms 2816 KB Output is correct
37 Correct 27 ms 5496 KB Output is correct
38 Correct 33 ms 5624 KB Output is correct
39 Correct 45 ms 5624 KB Output is correct
40 Correct 33 ms 5632 KB Output is correct
41 Correct 34 ms 5624 KB Output is correct
42 Correct 9 ms 2560 KB Output is correct
43 Correct 11 ms 2560 KB Output is correct
44 Correct 10 ms 2560 KB Output is correct
45 Correct 37 ms 8184 KB Output is correct
46 Correct 47 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2432 KB Output is correct
2 Correct 3 ms 2432 KB Output is correct
3 Correct 5 ms 2432 KB Output is correct
4 Correct 5 ms 2432 KB Output is correct
5 Correct 4 ms 2432 KB Output is correct
6 Correct 4 ms 2432 KB Output is correct
7 Correct 5 ms 2432 KB Output is correct
8 Correct 4 ms 2432 KB Output is correct
9 Correct 4 ms 2432 KB Output is correct
10 Correct 4 ms 2432 KB Output is correct
11 Correct 6 ms 2560 KB Output is correct
12 Correct 5 ms 2432 KB Output is correct
13 Correct 4 ms 2432 KB Output is correct
14 Correct 5 ms 2560 KB Output is correct
15 Correct 6 ms 2560 KB Output is correct
16 Correct 4 ms 2560 KB Output is correct
17 Correct 7 ms 2688 KB Output is correct
18 Correct 5 ms 2560 KB Output is correct
19 Correct 5 ms 2560 KB Output is correct
20 Correct 6 ms 2560 KB Output is correct
21 Correct 6 ms 2560 KB Output is correct
22 Correct 6 ms 2560 KB Output is correct
23 Correct 5 ms 2560 KB Output is correct
24 Correct 6 ms 2688 KB Output is correct
25 Correct 6 ms 2688 KB Output is correct
26 Correct 5 ms 2560 KB Output is correct
27 Correct 4 ms 2560 KB Output is correct
28 Correct 7 ms 2816 KB Output is correct
29 Correct 6 ms 3200 KB Output is correct
30 Correct 5 ms 2816 KB Output is correct
31 Correct 6 ms 2944 KB Output is correct
32 Correct 5 ms 2816 KB Output is correct
33 Correct 11 ms 3840 KB Output is correct
34 Correct 10 ms 3840 KB Output is correct
35 Correct 26 ms 4708 KB Output is correct
36 Correct 10 ms 2816 KB Output is correct
37 Correct 26 ms 5504 KB Output is correct
38 Correct 34 ms 5624 KB Output is correct
39 Correct 36 ms 5624 KB Output is correct
40 Correct 34 ms 5624 KB Output is correct
41 Correct 33 ms 5636 KB Output is correct
42 Correct 12 ms 2560 KB Output is correct
43 Correct 10 ms 2560 KB Output is correct
44 Correct 10 ms 2560 KB Output is correct
45 Correct 47 ms 8184 KB Output is correct
46 Correct 38 ms 8184 KB Output is correct
47 Correct 90 ms 12508 KB Output is correct
48 Correct 28 ms 6012 KB Output is correct
49 Correct 26 ms 4992 KB Output is correct
50 Correct 20 ms 4728 KB Output is correct
51 Correct 55 ms 7944 KB Output is correct
52 Correct 45 ms 8380 KB Output is correct
53 Correct 30 ms 4988 KB Output is correct
54 Correct 7 ms 3072 KB Output is correct
55 Correct 8 ms 3452 KB Output is correct
56 Correct 23 ms 4856 KB Output is correct
57 Correct 26 ms 11384 KB Output is correct
58 Correct 18 ms 3576 KB Output is correct
59 Correct 15 ms 3836 KB Output is correct
60 Correct 17 ms 4604 KB Output is correct
61 Correct 16 ms 3968 KB Output is correct
62 Correct 53 ms 9080 KB Output is correct
63 Correct 93 ms 25396 KB Output is correct
64 Correct 119 ms 28272 KB Output is correct
65 Correct 131 ms 38208 KB Output is correct
66 Correct 244 ms 65292 KB Output is correct
67 Correct 210 ms 65508 KB Output is correct