답안 #55150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55150 2018-07-06T06:37:31 Z 강태규(#1525) 날다람쥐 (JOI14_ho_t4) C++11
100 / 100
341 ms 76088 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const llong inf = 1e18;
int n, m, s;
int h[100001];
struct _edge {
    int x, c;
    _edge(int x, int c) : x(x), c(c) {}
};

struct node {
    int x;
    llong d;
    node(int x, llong d) : x(x), d(d) {}
    bool operator<(const node &p) const {
        return d > p.d;
    }
};

vector<_edge> edge[100001];
llong dist[100001];
int main() {
    scanf("%d%d%d", &n, &m, &s);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", h + i);
        dist[i] = inf;
    }
    for (int i = 0; i < m; ++i) {
        int a, b, t;
        scanf("%d%d%d", &a, &b, &t);
        if (t <= h[a]) edge[a].emplace_back(b, t);
        if (t <= h[b]) edge[b].emplace_back(a, t);
    }
    priority_queue<node> pq;
    pq.emplace(1, dist[1] = 0);
    while (!pq.empty()) {
        node t = pq.top();
        pq.pop();
        if (t.d != dist[t.x]) continue;
        for (_edge i : edge[t.x]) {
            llong d;
            if (s - t.d <= 0) d = t.d + i.c + i.c;
            else if (s - t.d - i.c <= 0) d = t.d + i.c - (s - t.d) + i.c;
            else if (s - t.d - i.c > h[i.x]) d = s - h[i.x];
            else d = t.d + i.c;
            if (d < dist[i.x])
                pq.emplace(i.x, dist[i.x] = d);
        }
    }
    llong ans;
    if (dist[n] == inf) ans = -1;
    else if (s - dist[n] <= 0) ans = dist[n] + h[n];
    else ans = dist[n] + h[n] - (s - dist[n]);
    printf("%lld\n", ans);
	return 0;
}

Compilation message

2014_ho_t4.cpp: In function 'int main()':
2014_ho_t4.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &m, &s);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
2014_ho_t4.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", h + i);
         ~~~~~^~~~~~~~~~~~~
2014_ho_t4.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &a, &b, &t);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 5 ms 2916 KB Output is correct
3 Correct 6 ms 2996 KB Output is correct
4 Correct 4 ms 2996 KB Output is correct
5 Correct 5 ms 2996 KB Output is correct
6 Correct 5 ms 2996 KB Output is correct
7 Correct 6 ms 2996 KB Output is correct
8 Correct 6 ms 3160 KB Output is correct
9 Correct 6 ms 3160 KB Output is correct
10 Correct 7 ms 3160 KB Output is correct
11 Correct 5 ms 3160 KB Output is correct
12 Correct 8 ms 3192 KB Output is correct
13 Correct 7 ms 3228 KB Output is correct
14 Correct 4 ms 3228 KB Output is correct
15 Correct 6 ms 3352 KB Output is correct
16 Correct 4 ms 3352 KB Output is correct
17 Correct 4 ms 3392 KB Output is correct
18 Correct 4 ms 3392 KB Output is correct
19 Correct 5 ms 3392 KB Output is correct
20 Correct 6 ms 3392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 314 ms 7488 KB Output is correct
2 Correct 276 ms 13064 KB Output is correct
3 Correct 195 ms 13064 KB Output is correct
4 Correct 333 ms 13368 KB Output is correct
5 Correct 173 ms 13368 KB Output is correct
6 Correct 12 ms 13368 KB Output is correct
7 Correct 150 ms 13368 KB Output is correct
8 Correct 341 ms 13368 KB Output is correct
9 Correct 185 ms 13368 KB Output is correct
10 Correct 131 ms 13368 KB Output is correct
11 Correct 28 ms 13368 KB Output is correct
12 Correct 178 ms 13368 KB Output is correct
13 Correct 70 ms 13368 KB Output is correct
14 Correct 197 ms 13368 KB Output is correct
15 Correct 11 ms 13368 KB Output is correct
16 Correct 286 ms 13368 KB Output is correct
17 Correct 33 ms 13368 KB Output is correct
18 Correct 43 ms 13368 KB Output is correct
19 Correct 80 ms 13368 KB Output is correct
20 Correct 39 ms 13368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 5 ms 2916 KB Output is correct
3 Correct 6 ms 2996 KB Output is correct
4 Correct 4 ms 2996 KB Output is correct
5 Correct 5 ms 2996 KB Output is correct
6 Correct 5 ms 2996 KB Output is correct
7 Correct 6 ms 2996 KB Output is correct
8 Correct 6 ms 3160 KB Output is correct
9 Correct 6 ms 3160 KB Output is correct
10 Correct 7 ms 3160 KB Output is correct
11 Correct 5 ms 3160 KB Output is correct
12 Correct 8 ms 3192 KB Output is correct
13 Correct 7 ms 3228 KB Output is correct
14 Correct 4 ms 3228 KB Output is correct
15 Correct 6 ms 3352 KB Output is correct
16 Correct 4 ms 3352 KB Output is correct
17 Correct 4 ms 3392 KB Output is correct
18 Correct 4 ms 3392 KB Output is correct
19 Correct 5 ms 3392 KB Output is correct
20 Correct 6 ms 3392 KB Output is correct
21 Correct 314 ms 7488 KB Output is correct
22 Correct 276 ms 13064 KB Output is correct
23 Correct 195 ms 13064 KB Output is correct
24 Correct 333 ms 13368 KB Output is correct
25 Correct 173 ms 13368 KB Output is correct
26 Correct 12 ms 13368 KB Output is correct
27 Correct 150 ms 13368 KB Output is correct
28 Correct 341 ms 13368 KB Output is correct
29 Correct 185 ms 13368 KB Output is correct
30 Correct 131 ms 13368 KB Output is correct
31 Correct 28 ms 13368 KB Output is correct
32 Correct 178 ms 13368 KB Output is correct
33 Correct 70 ms 13368 KB Output is correct
34 Correct 197 ms 13368 KB Output is correct
35 Correct 11 ms 13368 KB Output is correct
36 Correct 286 ms 13368 KB Output is correct
37 Correct 33 ms 13368 KB Output is correct
38 Correct 43 ms 13368 KB Output is correct
39 Correct 80 ms 13368 KB Output is correct
40 Correct 39 ms 13368 KB Output is correct
41 Correct 150 ms 13368 KB Output is correct
42 Correct 52 ms 13368 KB Output is correct
43 Correct 138 ms 15724 KB Output is correct
44 Correct 145 ms 21276 KB Output is correct
45 Correct 321 ms 30048 KB Output is correct
46 Correct 28 ms 30048 KB Output is correct
47 Correct 329 ms 35504 KB Output is correct
48 Correct 278 ms 40436 KB Output is correct
49 Correct 233 ms 42264 KB Output is correct
50 Correct 234 ms 48136 KB Output is correct
51 Correct 47 ms 48136 KB Output is correct
52 Correct 197 ms 50524 KB Output is correct
53 Correct 177 ms 51728 KB Output is correct
54 Correct 158 ms 58352 KB Output is correct
55 Correct 177 ms 62836 KB Output is correct
56 Correct 294 ms 74704 KB Output is correct
57 Correct 67 ms 74704 KB Output is correct
58 Correct 11 ms 74704 KB Output is correct
59 Correct 170 ms 74704 KB Output is correct
60 Correct 75 ms 76088 KB Output is correct