답안 #847176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
847176 2023-09-09T09:06:13 Z tuan13 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
247 ms 15576 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int ar = 3e4 + 5;
const int N = 105;
int n, m;
int vt[ar], p[ar];
int dp[ar][N];
vector<int> adj[ar];

struct tuan {
    int cost, u, step;
};

bool operator > (tuan a, tuan b) {
    return a.cost > b.cost;
}

void dijktra() {
    for(int i = 0; i < m; ++i) {
        adj[vt[i]].push_back(i);
    }
    priority_queue<tuan, vector<tuan>, greater<tuan>> q;
    memset(dp, 0x3f, sizeof(dp));
    dp[vt[0]][0] = 0;
    q.push({0, vt[0], 0});
    int ans = 1e9;
    while(q.size()) {
        tuan top = q.top(); q.pop();
        int u = top.u, cost = top.cost, step = top.step;
        if(cost > dp[u][step]) continue;
        if(step == 0) {
            for(int v : adj[u]) {
                if(p[v] >= N) {
                    int bonus = 0;
                    for(int i = u; i < n; i += p[v]) {
                        if(dp[i][0] > cost + bonus) {
                            dp[i][0] = cost + bonus;
                            q.push({dp[i][0], i, 0});
                        }
                        ++bonus;
                    }
                    bonus = 0;
                    for(int i = u; i >= 0; i -= p[v]) {
                        if(dp[i][0] > cost + bonus) {
                            dp[i][0] = cost + bonus;
                            q.push({dp[i][0], i, 0});
                        }
                        ++bonus;
                    }
                }
                else {
                    if(dp[u][p[v]] > cost) {
                        dp[u][p[v]] = cost;
                        q.push({dp[u][p[v]], u, p[v]});
                    }
                }
            }
        }
        else {
            if(u - step >= 0 && dp[u - step][step] > cost + 1) {
                dp[u - step][step] = cost + 1;
                q.push({dp[u - step][step], u - step, step});
            }
            if(u + step < n && dp[u + step][step] > cost + 1) {
                dp[u + step][step] = cost + 1;
                q.push({dp[u + step][step], u + step, step});
            }
            if(dp[u][0] > cost) {
                dp[u][0] = cost;
                q.push({dp[u][0], u, 0});
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; ++i) {
        cin >> vt[i] >> p[i];
    }
    dijktra();
    int ans = 1e9;
    for(int i = 0; i < N; ++i) {
        ans = min(ans, dp[vt[1]][i]);
    }
    if(ans == 1e9) ans = -1;
    cout << ans;
}

Compilation message

skyscraper.cpp: In function 'void dijktra()':
skyscraper.cpp:27:9: warning: unused variable 'ans' [-Wunused-variable]
   27 |     int ans = 1e9;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13404 KB Output is correct
2 Correct 2 ms 13404 KB Output is correct
3 Correct 2 ms 13404 KB Output is correct
4 Correct 2 ms 13404 KB Output is correct
5 Correct 2 ms 13404 KB Output is correct
6 Correct 4 ms 13460 KB Output is correct
7 Correct 2 ms 13404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13404 KB Output is correct
2 Correct 2 ms 13404 KB Output is correct
3 Correct 2 ms 13404 KB Output is correct
4 Correct 2 ms 13404 KB Output is correct
5 Correct 2 ms 13400 KB Output is correct
6 Correct 2 ms 13656 KB Output is correct
7 Correct 2 ms 13404 KB Output is correct
8 Correct 2 ms 13404 KB Output is correct
9 Correct 2 ms 13404 KB Output is correct
10 Correct 2 ms 13404 KB Output is correct
11 Correct 3 ms 13404 KB Output is correct
12 Correct 2 ms 13404 KB Output is correct
13 Correct 2 ms 13404 KB Output is correct
14 Correct 3 ms 13404 KB Output is correct
15 Correct 3 ms 13404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 13404 KB Output is correct
2 Correct 3 ms 13448 KB Output is correct
3 Correct 2 ms 13404 KB Output is correct
4 Correct 3 ms 13404 KB Output is correct
5 Correct 2 ms 13404 KB Output is correct
6 Correct 2 ms 13404 KB Output is correct
7 Correct 2 ms 13404 KB Output is correct
8 Correct 2 ms 13404 KB Output is correct
9 Correct 4 ms 13404 KB Output is correct
10 Correct 3 ms 13404 KB Output is correct
11 Correct 3 ms 13404 KB Output is correct
12 Correct 2 ms 13404 KB Output is correct
13 Correct 3 ms 13404 KB Output is correct
14 Correct 3 ms 13404 KB Output is correct
15 Correct 3 ms 13404 KB Output is correct
16 Correct 2 ms 13404 KB Output is correct
17 Correct 3 ms 13404 KB Output is correct
18 Correct 3 ms 13404 KB Output is correct
19 Correct 2 ms 13404 KB Output is correct
20 Correct 3 ms 13404 KB Output is correct
21 Correct 2 ms 13404 KB Output is correct
22 Correct 2 ms 13404 KB Output is correct
23 Correct 2 ms 13404 KB Output is correct
24 Correct 3 ms 13404 KB Output is correct
25 Correct 3 ms 13404 KB Output is correct
26 Correct 2 ms 13404 KB Output is correct
27 Correct 2 ms 13404 KB Output is correct
28 Correct 3 ms 13404 KB Output is correct
29 Correct 5 ms 13400 KB Output is correct
30 Correct 3 ms 13404 KB Output is correct
31 Correct 4 ms 13404 KB Output is correct
32 Correct 3 ms 13404 KB Output is correct
33 Correct 9 ms 13576 KB Output is correct
34 Correct 9 ms 13400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 13404 KB Output is correct
2 Correct 2 ms 13404 KB Output is correct
3 Correct 2 ms 13404 KB Output is correct
4 Correct 2 ms 13404 KB Output is correct
5 Correct 2 ms 13404 KB Output is correct
6 Correct 2 ms 13400 KB Output is correct
7 Correct 2 ms 13404 KB Output is correct
8 Correct 2 ms 13404 KB Output is correct
9 Correct 3 ms 13404 KB Output is correct
10 Correct 2 ms 13404 KB Output is correct
11 Correct 3 ms 13404 KB Output is correct
12 Correct 2 ms 13404 KB Output is correct
13 Correct 2 ms 13400 KB Output is correct
14 Correct 3 ms 13404 KB Output is correct
15 Correct 3 ms 13496 KB Output is correct
16 Correct 2 ms 13404 KB Output is correct
17 Correct 3 ms 13404 KB Output is correct
18 Correct 2 ms 13404 KB Output is correct
19 Correct 2 ms 13404 KB Output is correct
20 Correct 2 ms 13404 KB Output is correct
21 Correct 2 ms 13488 KB Output is correct
22 Correct 2 ms 13404 KB Output is correct
23 Correct 3 ms 13404 KB Output is correct
24 Correct 3 ms 13400 KB Output is correct
25 Correct 3 ms 13404 KB Output is correct
26 Correct 3 ms 13404 KB Output is correct
27 Correct 2 ms 13500 KB Output is correct
28 Correct 3 ms 13404 KB Output is correct
29 Correct 5 ms 13400 KB Output is correct
30 Correct 4 ms 13660 KB Output is correct
31 Correct 4 ms 13404 KB Output is correct
32 Correct 3 ms 13404 KB Output is correct
33 Correct 9 ms 13580 KB Output is correct
34 Correct 9 ms 13572 KB Output is correct
35 Correct 9 ms 13916 KB Output is correct
36 Correct 4 ms 13404 KB Output is correct
37 Correct 11 ms 14004 KB Output is correct
38 Correct 14 ms 14104 KB Output is correct
39 Correct 12 ms 13916 KB Output is correct
40 Correct 11 ms 13916 KB Output is correct
41 Correct 12 ms 14056 KB Output is correct
42 Correct 6 ms 13916 KB Output is correct
43 Correct 5 ms 13916 KB Output is correct
44 Correct 5 ms 13912 KB Output is correct
45 Correct 19 ms 14172 KB Output is correct
46 Correct 18 ms 14168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 13400 KB Output is correct
2 Correct 2 ms 13404 KB Output is correct
3 Correct 2 ms 13404 KB Output is correct
4 Correct 2 ms 13404 KB Output is correct
5 Correct 2 ms 13404 KB Output is correct
6 Correct 2 ms 13404 KB Output is correct
7 Correct 2 ms 13404 KB Output is correct
8 Correct 2 ms 13404 KB Output is correct
9 Correct 2 ms 13404 KB Output is correct
10 Correct 2 ms 13404 KB Output is correct
11 Correct 3 ms 13404 KB Output is correct
12 Correct 2 ms 13352 KB Output is correct
13 Correct 2 ms 13404 KB Output is correct
14 Correct 3 ms 13404 KB Output is correct
15 Correct 3 ms 13400 KB Output is correct
16 Correct 2 ms 13400 KB Output is correct
17 Correct 3 ms 13496 KB Output is correct
18 Correct 2 ms 13404 KB Output is correct
19 Correct 2 ms 13404 KB Output is correct
20 Correct 2 ms 13404 KB Output is correct
21 Correct 2 ms 13652 KB Output is correct
22 Correct 2 ms 13404 KB Output is correct
23 Correct 2 ms 13404 KB Output is correct
24 Correct 3 ms 13404 KB Output is correct
25 Correct 3 ms 13400 KB Output is correct
26 Correct 3 ms 13404 KB Output is correct
27 Correct 3 ms 13504 KB Output is correct
28 Correct 3 ms 13404 KB Output is correct
29 Correct 5 ms 13464 KB Output is correct
30 Correct 3 ms 13404 KB Output is correct
31 Correct 4 ms 13404 KB Output is correct
32 Correct 3 ms 13404 KB Output is correct
33 Correct 9 ms 13584 KB Output is correct
34 Correct 9 ms 13404 KB Output is correct
35 Correct 9 ms 13996 KB Output is correct
36 Correct 5 ms 13404 KB Output is correct
37 Correct 11 ms 14000 KB Output is correct
38 Correct 12 ms 13916 KB Output is correct
39 Correct 12 ms 13912 KB Output is correct
40 Correct 12 ms 13912 KB Output is correct
41 Correct 13 ms 13916 KB Output is correct
42 Correct 6 ms 13916 KB Output is correct
43 Correct 5 ms 13916 KB Output is correct
44 Correct 5 ms 13912 KB Output is correct
45 Correct 19 ms 14168 KB Output is correct
46 Correct 19 ms 14172 KB Output is correct
47 Correct 34 ms 14424 KB Output is correct
48 Correct 6 ms 13916 KB Output is correct
49 Correct 6 ms 13916 KB Output is correct
50 Correct 5 ms 13916 KB Output is correct
51 Correct 23 ms 14716 KB Output is correct
52 Correct 26 ms 14676 KB Output is correct
53 Correct 10 ms 14172 KB Output is correct
54 Correct 3 ms 13404 KB Output is correct
55 Correct 3 ms 13400 KB Output is correct
56 Correct 9 ms 14428 KB Output is correct
57 Correct 33 ms 13596 KB Output is correct
58 Correct 6 ms 13916 KB Output is correct
59 Correct 8 ms 13916 KB Output is correct
60 Correct 9 ms 13916 KB Output is correct
61 Correct 8 ms 13916 KB Output is correct
62 Correct 17 ms 14660 KB Output is correct
63 Correct 21 ms 15576 KB Output is correct
64 Correct 21 ms 15576 KB Output is correct
65 Correct 34 ms 15576 KB Output is correct
66 Correct 247 ms 15568 KB Output is correct
67 Correct 234 ms 15572 KB Output is correct