답안 #1100458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100458 2024-10-14T02:59:49 Z vjudge1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
624 ms 14268 KB
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)
 
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
 
 
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/
 
template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }
 
template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX                     30005
int numHouse, numDoge;
set<int> G[MAX];
int pos[MAX], power[MAX], minDist[MAX];
void process(void){
    int from, to;
    cin >> numHouse >> numDoge;
    for (int i = 1; i <= numDoge; ++i){
        cin >> pos[i] >> power[i];
        ++pos[i];
        G[pos[i]].insert(power[i]);
        if(i == 1){
            from = pos[i];
        }
        if(i == 2){
            to = pos[i];
        }
    }
 
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
 
    memset(minDist, 0x3f, sizeof minDist);
 
    q.emplace(0, from);
    minDist[from] = 0;
    while(q.size()){
        int du, u; tie(du, u) = q.top(); q.pop();
        if(du > minDist[u]) continue;
 
        for (auto&v : G[u]){
            for (int i = 1; u + v * i <= numHouse; ++i){
                if(minimize(minDist[u + v * i], minDist[u] + i)){
                    q.emplace(minDist[u + v * i], u + v * i);
                }
            }
            for (int i = -1; u + v * i >= 1; --i){
                if(minimize(minDist[u + v * i], minDist[u] - i)){
                    q.emplace(minDist[u + v * i], u + v * i);
                }
            }
        }
    }
    cout << (minDist[to] >= LINF ? -1 : minDist[to]);
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    process();
    return (0 ^ 0);
}

Compilation message

skyscraper.cpp: In function 'void process()':
skyscraper.cpp:62:19: warning: 'from' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |     minDist[from] = 0;
      |     ~~~~~~~~~~~~~~^~~
skyscraper.cpp:80:24: warning: 'to' may be used uninitialized in this function [-Wmaybe-uninitialized]
   80 |     cout << (minDist[to] >= LINF ? -1 : minDist[to]);
      |              ~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 1 ms 1872 KB Output is correct
4 Correct 1 ms 1872 KB Output is correct
5 Correct 1 ms 1872 KB Output is correct
6 Correct 1 ms 1872 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 1884 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 1 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 1 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 2 ms 2128 KB Output is correct
11 Correct 3 ms 2128 KB Output is correct
12 Correct 2 ms 2128 KB Output is correct
13 Correct 2 ms 2128 KB Output is correct
14 Correct 2 ms 2128 KB Output is correct
15 Correct 2 ms 2128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 1 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 1 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 1 ms 2064 KB Output is correct
9 Correct 1 ms 1872 KB Output is correct
10 Correct 2 ms 2296 KB Output is correct
11 Correct 2 ms 2128 KB Output is correct
12 Correct 2 ms 2128 KB Output is correct
13 Correct 2 ms 2128 KB Output is correct
14 Correct 2 ms 2128 KB Output is correct
15 Correct 2 ms 2128 KB Output is correct
16 Correct 2 ms 2128 KB Output is correct
17 Correct 2 ms 2128 KB Output is correct
18 Correct 2 ms 2128 KB Output is correct
19 Correct 3 ms 2296 KB Output is correct
20 Correct 5 ms 2304 KB Output is correct
21 Correct 2 ms 2128 KB Output is correct
22 Correct 2 ms 2128 KB Output is correct
23 Correct 2 ms 2128 KB Output is correct
24 Correct 2 ms 2128 KB Output is correct
25 Correct 2 ms 2128 KB Output is correct
26 Correct 2 ms 2128 KB Output is correct
27 Correct 2 ms 2128 KB Output is correct
28 Correct 2 ms 2200 KB Output is correct
29 Correct 4 ms 2384 KB Output is correct
30 Correct 3 ms 2128 KB Output is correct
31 Correct 3 ms 2384 KB Output is correct
32 Correct 2 ms 2132 KB Output is correct
33 Correct 5 ms 2936 KB Output is correct
34 Correct 4 ms 2776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 1 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 1 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 2128 KB Output is correct
11 Correct 2 ms 2128 KB Output is correct
12 Correct 2 ms 2128 KB Output is correct
13 Correct 2 ms 2128 KB Output is correct
14 Correct 2 ms 2128 KB Output is correct
15 Correct 2 ms 2128 KB Output is correct
16 Correct 2 ms 2128 KB Output is correct
17 Correct 2 ms 2128 KB Output is correct
18 Correct 2 ms 2128 KB Output is correct
19 Correct 2 ms 2128 KB Output is correct
20 Correct 5 ms 2128 KB Output is correct
21 Correct 2 ms 2308 KB Output is correct
22 Correct 2 ms 2296 KB Output is correct
23 Correct 2 ms 2128 KB Output is correct
24 Correct 2 ms 2128 KB Output is correct
25 Correct 2 ms 2128 KB Output is correct
26 Correct 2 ms 2128 KB Output is correct
27 Correct 2 ms 2128 KB Output is correct
28 Correct 2 ms 2128 KB Output is correct
29 Correct 3 ms 2384 KB Output is correct
30 Correct 3 ms 2128 KB Output is correct
31 Correct 3 ms 2384 KB Output is correct
32 Correct 2 ms 2128 KB Output is correct
33 Correct 4 ms 2764 KB Output is correct
34 Correct 5 ms 2764 KB Output is correct
35 Correct 9 ms 3760 KB Output is correct
36 Correct 3 ms 2384 KB Output is correct
37 Correct 11 ms 3416 KB Output is correct
38 Correct 10 ms 4176 KB Output is correct
39 Correct 10 ms 4176 KB Output is correct
40 Correct 10 ms 4176 KB Output is correct
41 Correct 10 ms 4176 KB Output is correct
42 Correct 4 ms 2384 KB Output is correct
43 Correct 4 ms 2384 KB Output is correct
44 Correct 7 ms 2640 KB Output is correct
45 Correct 12 ms 4572 KB Output is correct
46 Correct 12 ms 4556 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 1 ms 1872 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 2 ms 1884 KB Output is correct
8 Correct 2 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 2 ms 2140 KB Output is correct
11 Correct 2 ms 2140 KB Output is correct
12 Correct 2 ms 2140 KB Output is correct
13 Correct 2 ms 2140 KB Output is correct
14 Correct 2 ms 2140 KB Output is correct
15 Correct 2 ms 2140 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 3 ms 2140 KB Output is correct
18 Correct 2 ms 2140 KB Output is correct
19 Correct 2 ms 2140 KB Output is correct
20 Correct 5 ms 2140 KB Output is correct
21 Correct 2 ms 2140 KB Output is correct
22 Correct 2 ms 2140 KB Output is correct
23 Correct 2 ms 2140 KB Output is correct
24 Correct 2 ms 2140 KB Output is correct
25 Correct 2 ms 2296 KB Output is correct
26 Correct 2 ms 2140 KB Output is correct
27 Correct 2 ms 2140 KB Output is correct
28 Correct 2 ms 2128 KB Output is correct
29 Correct 3 ms 2384 KB Output is correct
30 Correct 2 ms 2128 KB Output is correct
31 Correct 2 ms 2384 KB Output is correct
32 Correct 2 ms 2128 KB Output is correct
33 Correct 5 ms 2764 KB Output is correct
34 Correct 4 ms 2764 KB Output is correct
35 Correct 8 ms 3644 KB Output is correct
36 Correct 3 ms 2384 KB Output is correct
37 Correct 7 ms 3408 KB Output is correct
38 Correct 10 ms 4348 KB Output is correct
39 Correct 10 ms 4176 KB Output is correct
40 Correct 10 ms 4176 KB Output is correct
41 Correct 10 ms 4176 KB Output is correct
42 Correct 4 ms 2384 KB Output is correct
43 Correct 5 ms 2384 KB Output is correct
44 Correct 7 ms 2640 KB Output is correct
45 Correct 14 ms 4556 KB Output is correct
46 Correct 13 ms 4556 KB Output is correct
47 Correct 15 ms 4552 KB Output is correct
48 Correct 6 ms 3408 KB Output is correct
49 Correct 6 ms 3408 KB Output is correct
50 Correct 4 ms 2896 KB Output is correct
51 Correct 21 ms 7276 KB Output is correct
52 Correct 21 ms 5064 KB Output is correct
53 Correct 12 ms 5064 KB Output is correct
54 Correct 3 ms 2384 KB Output is correct
55 Correct 3 ms 2384 KB Output is correct
56 Correct 624 ms 4556 KB Output is correct
57 Correct 35 ms 8388 KB Output is correct
58 Correct 6 ms 2896 KB Output is correct
59 Correct 6 ms 2896 KB Output is correct
60 Correct 7 ms 2896 KB Output is correct
61 Correct 9 ms 3028 KB Output is correct
62 Correct 8 ms 3920 KB Output is correct
63 Correct 32 ms 10176 KB Output is correct
64 Correct 31 ms 10176 KB Output is correct
65 Correct 38 ms 10176 KB Output is correct
66 Correct 73 ms 14268 KB Output is correct
67 Correct 73 ms 14268 KB Output is correct