답안 #1110734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110734 2024-11-10T09:42:02 Z vjudge1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
22 / 100
6 ms 2296 KB
/**------------------------------------------
---------Author: BePhuong--------------------
---------From: TK4-CHT ----------------------
---------Training To Win Voi 25 !!! ---------
---------------------------------------------
--------------------PhamVuPhuong2008<BeL>-**/

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define int long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii, ii>
#define base 341
#define MASK(i) (1ll << i)
#define oo 1e18
#define isOn(x,i) ((x) & MASK(i))
#define bitOn(x,i) ((x) | MASK(i))
#define bitOff(x,i) ((x) & ~MASK(i))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
using namespace std;
//using namespace __gnu_pbds;
const int maxn = 5e4 + 5;
int n,m,  dist[maxn], b[maxn];
vector<int> a[maxn];
void djk(int st) {
    memset(dist, 0x3f, sizeof dist);
    priority_queue<ii, vector<ii>, greater<ii>> q;
    dist[st] = 0;
    q.push({0, st});
    while(!q.empty()) {
        int cost = q.top().fi, z = q.top().se;
//        int z = q.front();
        q.pop();
        if (cost > dist[z]) continue;
        for (int cost : a[z]) {
            for (int i = 1; z + i*cost < n; i++) {
                if (dist[z + i*cost] > dist[z] + i) {
                    dist[z + i*cost] = dist[z] + i;
                    q.push({dist[z + i*cost], z + i*cost});
                }
            }
            for (int i = 1; z - i*cost > 0; i++) {
                if (dist[z - i*cost] > dist[z] + i) {
                    dist[z - i*cost] = dist[z] + i;
                    q.push({dist[z - i*cost], z - i*cost});
                }
            }
        }
    }
}
main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        int x; cin >> x;
        a[b[i]].pb(x);
    }
   // for (int i = 0; i < m; i++) cout << b[i] << endl;
    djk(b[0]);
    if (dist[b[1]] >= 1e15) cout << "-1";
    else cout << dist[b[1]];
}

Compilation message

skyscraper.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 2 ms 2048 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1924 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 1 ms 1872 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 2 ms 1872 KB Output is correct
11 Correct 2 ms 1872 KB Output is correct
12 Correct 2 ms 1872 KB Output is correct
13 Correct 2 ms 1872 KB Output is correct
14 Correct 2 ms 1900 KB Output is correct
15 Correct 2 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 2 ms 2048 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 2 ms 1872 KB Output is correct
11 Correct 2 ms 1872 KB Output is correct
12 Correct 3 ms 1872 KB Output is correct
13 Correct 2 ms 1872 KB Output is correct
14 Correct 2 ms 2012 KB Output is correct
15 Correct 3 ms 2040 KB Output is correct
16 Correct 2 ms 1872 KB Output is correct
17 Correct 3 ms 2128 KB Output is correct
18 Correct 2 ms 1872 KB Output is correct
19 Correct 2 ms 1872 KB Output is correct
20 Correct 6 ms 2176 KB Output is correct
21 Correct 2 ms 1872 KB Output is correct
22 Correct 2 ms 1872 KB Output is correct
23 Correct 2 ms 1872 KB Output is correct
24 Correct 3 ms 2128 KB Output is correct
25 Correct 3 ms 2296 KB Output is correct
26 Correct 5 ms 1872 KB Output is correct
27 Correct 5 ms 1872 KB Output is correct
28 Incorrect 2 ms 1872 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 2 ms 1872 KB Output is correct
11 Correct 2 ms 1872 KB Output is correct
12 Correct 2 ms 2020 KB Output is correct
13 Correct 3 ms 1872 KB Output is correct
14 Correct 2 ms 1872 KB Output is correct
15 Correct 2 ms 1900 KB Output is correct
16 Correct 2 ms 1872 KB Output is correct
17 Correct 2 ms 2128 KB Output is correct
18 Correct 2 ms 1872 KB Output is correct
19 Correct 2 ms 1872 KB Output is correct
20 Correct 5 ms 2128 KB Output is correct
21 Correct 2 ms 1872 KB Output is correct
22 Correct 2 ms 1872 KB Output is correct
23 Correct 2 ms 2048 KB Output is correct
24 Correct 2 ms 2128 KB Output is correct
25 Correct 2 ms 2128 KB Output is correct
26 Correct 5 ms 1872 KB Output is correct
27 Correct 4 ms 1872 KB Output is correct
28 Incorrect 2 ms 1872 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 2044 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
8 Correct 2 ms 2100 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 2 ms 1872 KB Output is correct
11 Correct 2 ms 1872 KB Output is correct
12 Correct 3 ms 1972 KB Output is correct
13 Correct 3 ms 1872 KB Output is correct
14 Correct 2 ms 1872 KB Output is correct
15 Correct 2 ms 1872 KB Output is correct
16 Correct 2 ms 1872 KB Output is correct
17 Correct 2 ms 2128 KB Output is correct
18 Correct 2 ms 1872 KB Output is correct
19 Correct 2 ms 1872 KB Output is correct
20 Correct 5 ms 2296 KB Output is correct
21 Correct 2 ms 1872 KB Output is correct
22 Correct 2 ms 1872 KB Output is correct
23 Correct 2 ms 1872 KB Output is correct
24 Correct 3 ms 2196 KB Output is correct
25 Correct 2 ms 2296 KB Output is correct
26 Correct 4 ms 1872 KB Output is correct
27 Correct 4 ms 1872 KB Output is correct
28 Incorrect 2 ms 1872 KB Output isn't correct
29 Halted 0 ms 0 KB -