답안 #768351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768351 2023-06-28T00:46:35 Z hgmhc 날다람쥐 (JOI14_ho_t4) C++17
25 / 100
7 ms 1384 KB
#include <bits/stdc++.h>
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)
#define all(x) begin(x),end(x)
#define per(i,a,b) for (auto i = (b); i >= (a); --i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define mp make_pair

const ll INF = 1e18;
const int N = 1003, H = 103;
int n, m, x, h[N];
vector<ii> adj[N];
ll dist[N][H];

int main() {
    scanf("%d%d%d", &n, &m, &x);
    rep(i,1,n) scanf("%d", &h[i]), assert(h[i] <= 100);
    rep(i,1,m) {
        int u, v, t;
        scanf("%d%d%d", &u, &v, &t);
        adj[u].push_back({v,t});
        adj[v].push_back({u,t});
    }
    fill(dist[0],dist[N],INF);
    priority_queue<tuple<ll,int,int>> pq;
    dist[1][x] = 0, pq.push({0,1,x});
    while (not empty(pq)) {
        auto [d,a,x] = pq.top(); pq.pop(), d=-d;
        if (dist[a][x] < d) continue;
        if (0 < x and dist[a][x-1] > dist[a][x]+1) {
            dist[a][x-1] = dist[a][x]+1;
            pq.push({-dist[a][x-1],a,x-1});
        }
        if (x < h[a] and dist[a][x+1] > dist[a][x]+1) {
            dist[a][x+1] = dist[a][x]+1;
            pq.push({-dist[a][x+1],a,x+1});
        }
        for (auto [b,w] : adj[a]) {
            if (0 <= x-w and x-w <= h[b]) {
                if (dist[b][x-w] > dist[a][x]+w) {
                    dist[b][x-w] = dist[a][x]+w;
                    pq.push({-dist[b][x-w],b,x-w});
                }
            }
        }
    }
    if (dist[n][h[n]] >= INF) puts("-1");
    else printf("%lld", dist[n][h[n]]);
}

Compilation message

2014_ho_t4.cpp: In function 'int main()':
2014_ho_t4.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d%d%d", &n, &m, &x);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
2014_ho_t4.cpp:21:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     rep(i,1,n) scanf("%d", &h[i]), assert(h[i] <= 100);
      |                ~~~~~^~~~~~~~~~~~~
2014_ho_t4.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%d%d%d", &u, &v, &t);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1108 KB Output is correct
2 Correct 7 ms 1384 KB Output is correct
3 Correct 6 ms 1292 KB Output is correct
4 Correct 3 ms 1108 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 2 ms 1108 KB Output is correct
8 Correct 6 ms 1376 KB Output is correct
9 Correct 4 ms 1364 KB Output is correct
10 Correct 5 ms 1364 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 6 ms 1300 KB Output is correct
13 Correct 6 ms 1380 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 4 ms 1364 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 2 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 3 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1108 KB Output is correct
2 Correct 7 ms 1384 KB Output is correct
3 Correct 6 ms 1292 KB Output is correct
4 Correct 3 ms 1108 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 2 ms 1108 KB Output is correct
8 Correct 6 ms 1376 KB Output is correct
9 Correct 4 ms 1364 KB Output is correct
10 Correct 5 ms 1364 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 6 ms 1300 KB Output is correct
13 Correct 6 ms 1380 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 4 ms 1364 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 2 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 3 ms 1108 KB Output is correct
21 Runtime error 1 ms 468 KB Execution killed with signal 6
22 Halted 0 ms 0 KB -