답안 #1097444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097444 2024-10-07T11:54:03 Z Kerim Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
474 ms 12064 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define right sag
#define left cep
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 3e4+5;
const ll INF = 1e18;
set<int> adj[N];
ll dis[N];
 
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int s, t;
    for(int i = 1; i <= m; ++i){
        int x, p;
        scanf("%d%d", &x, &p), x++;
        if (i == 1)
            s = x;
        if (i == 2)
            t = x;
        adj[x].insert(p);
    }
    for(int i = 1; i <= n; ++i)
        dis[i] = INF;
    priority_queue<pli, vector<pli>, greater<pli>> pq;
    pq.push({0, s});
    dis[s] = 0;
    while(!pq.empty()){
        pli P = pq.top();
        pq.pop();
        ll val = P.ff;
        int x = P.ss;
        if(dis[x] != val)
            continue;
        for (auto p: adj[x]){
            for (int i = 1; x - i * p >= 1; i++){
                int to = x - i * p;
                if (umin(dis[to], val + i))
                    pq.push({dis[to], to});
            }
            for (int i = 1; x + i * p <= n; i++){
                int to = x + i * p;
                if (umin(dis[to], val + i))
                    pq.push({dis[to], to});
            }
        }
    }
    if(dis[t] == INF)
        puts("-1");
    else
        printf("%lld\n", dis[t]);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d%d", &x, &p), x++;
      |         ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:39:12: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |     dis[s] = 0;
      |     ~~~~~~~^~~
skyscraper.cpp:60:13: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     if(dis[t] == INF)
      |        ~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1624 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1624 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1624 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1628 KB Output is correct
13 Correct 1 ms 1624 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1836 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1628 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 4 ms 1884 KB Output is correct
21 Correct 1 ms 1880 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 1 ms 1884 KB Output is correct
24 Correct 2 ms 1884 KB Output is correct
25 Correct 1 ms 1884 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 1 ms 1884 KB Output is correct
28 Correct 1 ms 1884 KB Output is correct
29 Correct 2 ms 2140 KB Output is correct
30 Correct 1 ms 1948 KB Output is correct
31 Correct 2 ms 2032 KB Output is correct
32 Correct 1 ms 1884 KB Output is correct
33 Correct 4 ms 2528 KB Output is correct
34 Correct 4 ms 2528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1624 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1628 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 3 ms 2016 KB Output is correct
21 Correct 1 ms 1880 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 1 ms 1884 KB Output is correct
24 Correct 1 ms 1884 KB Output is correct
25 Correct 2 ms 1880 KB Output is correct
26 Correct 1 ms 1880 KB Output is correct
27 Correct 1 ms 1884 KB Output is correct
28 Correct 2 ms 1884 KB Output is correct
29 Correct 2 ms 2244 KB Output is correct
30 Correct 1 ms 1884 KB Output is correct
31 Correct 2 ms 2032 KB Output is correct
32 Correct 1 ms 1884 KB Output is correct
33 Correct 4 ms 2528 KB Output is correct
34 Correct 4 ms 2564 KB Output is correct
35 Correct 8 ms 3100 KB Output is correct
36 Correct 2 ms 2140 KB Output is correct
37 Correct 7 ms 2984 KB Output is correct
38 Correct 10 ms 3420 KB Output is correct
39 Correct 10 ms 3280 KB Output is correct
40 Correct 11 ms 3420 KB Output is correct
41 Correct 11 ms 3420 KB Output is correct
42 Correct 4 ms 1852 KB Output is correct
43 Correct 4 ms 1884 KB Output is correct
44 Correct 7 ms 1884 KB Output is correct
45 Correct 15 ms 3804 KB Output is correct
46 Correct 12 ms 3804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1628 KB Output is correct
13 Correct 1 ms 1628 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 4 ms 2024 KB Output is correct
21 Correct 2 ms 1880 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 1 ms 1884 KB Output is correct
24 Correct 3 ms 1884 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 1 ms 1884 KB Output is correct
27 Correct 1 ms 1884 KB Output is correct
28 Correct 2 ms 1884 KB Output is correct
29 Correct 3 ms 2140 KB Output is correct
30 Correct 1 ms 1884 KB Output is correct
31 Correct 2 ms 2032 KB Output is correct
32 Correct 1 ms 1884 KB Output is correct
33 Correct 4 ms 2528 KB Output is correct
34 Correct 4 ms 2528 KB Output is correct
35 Correct 8 ms 3080 KB Output is correct
36 Correct 2 ms 2140 KB Output is correct
37 Correct 7 ms 2936 KB Output is correct
38 Correct 10 ms 3488 KB Output is correct
39 Correct 10 ms 3312 KB Output is correct
40 Correct 10 ms 3304 KB Output is correct
41 Correct 10 ms 3416 KB Output is correct
42 Correct 4 ms 1852 KB Output is correct
43 Correct 4 ms 1884 KB Output is correct
44 Correct 7 ms 1884 KB Output is correct
45 Correct 14 ms 3704 KB Output is correct
46 Correct 12 ms 3808 KB Output is correct
47 Correct 15 ms 4420 KB Output is correct
48 Correct 6 ms 3316 KB Output is correct
49 Correct 5 ms 3176 KB Output is correct
50 Correct 4 ms 2916 KB Output is correct
51 Correct 21 ms 5844 KB Output is correct
52 Correct 20 ms 4824 KB Output is correct
53 Correct 13 ms 4824 KB Output is correct
54 Correct 2 ms 2392 KB Output is correct
55 Correct 3 ms 2396 KB Output is correct
56 Correct 474 ms 4300 KB Output is correct
57 Correct 41 ms 6352 KB Output is correct
58 Correct 7 ms 2516 KB Output is correct
59 Correct 6 ms 2596 KB Output is correct
60 Correct 7 ms 2652 KB Output is correct
61 Correct 7 ms 2776 KB Output is correct
62 Correct 8 ms 3676 KB Output is correct
63 Correct 35 ms 7744 KB Output is correct
64 Correct 39 ms 7888 KB Output is correct
65 Correct 50 ms 7884 KB Output is correct
66 Correct 84 ms 12064 KB Output is correct
67 Correct 82 ms 11980 KB Output is correct