Submission #00002
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include<bits/stdc++.h> using namespace std; #define INF ((lld)1<<55) typedef long long int lld; typedef pair< int ,lld> P; typedef pair<lld,P> Pi; lld N,M,X; lld H[100001]; vector<P> edge[100001]; lld min_cost[100001]; int main(){ cin >> N >> M >> X; for ( int i=0;i<N;i++){ cin >> H[i]; } for ( int i=0;i<M;i++){ int a,b; lld c; cin >> a >> b >> c; a--; b--; edge[a].push_back(P(b,c)); edge[b].push_back(P(a,c)); } fill_n(min_cost,100001,INF); priority_queue<Pi,vector<Pi>,greater<Pi> > que; min_cost[0] = 0; que.push(Pi(0,P(0,X))); while (!que.empty()){ Pi p = que.top(); que.pop(); lld cost = p.first; int now = p.second.first; lld high = p.second.second; if (min_cost[now] < cost) continue ; if (now == N-1) continue ; for ( int i=0;i<edge[now].size();i++){ int next = edge[now][i].first; lld nh = edge[now][i].second; lld nc = cost; if (high - nh <= H[next] && high - nh >= 0){ if (next == N-1) nc += H[next] - (high-nh); if (min_cost[next] > nc + nh){ que.push(Pi(nc+nh,P(next,high-nh))); min_cost[next] = nc + nh; } } else if (high - nh > H[next]){ lld down = (high - nh) - H[next]; if (next == N-1) nc += H[next] - (high-nh-down); if (high - down >= 0){ if (min_cost[next] > nc + nh + down){ que.push(Pi(nc+nh+down,P(next,high-nh-down))); min_cost[next] = nc + nh + down; } } } else { lld up = llabs(high - nh); if (next == N-1) nc += H[next] - (high-nh+up); if (high + up <= H[now]){ if (min_cost[next] > nc + nh + up){ que.push(Pi(nc+nh+up,P(next,high-nh+up))); min_cost[next] = nc + nh + up; } } } } } if (min_cost[N-1] == INF) cout << "-1" << endl; else cout << min_cost[N-1] << endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0001 - フクロモモンガ (Sugar Glider) |
ユーザー名 | ei1428 |
投稿日時 | 2016-01-20 16:55:34 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 1837 Byte |
最大実行時間 | 322 ms |
最大メモリ使用量 | 22212 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | Subtask1 | 25 / 25 | 01-* |
2 | Subtask2 | 25 / 25 | 02-* |
3 | Subtask3 | 50 / 50 | 01-*, 02-*, 03-* |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | ||
---|---|---|---|---|---|---|
01-01.txt | AC | 16 ms | 3676 KB |
1
|
3
|
|
01-02.txt | AC | 16 ms | 3788 KB |
1
|
3
|
|
01-03.txt | AC | 14 ms | 3900 KB |
1
|
3
|
|
01-04.txt | AC | 15 ms | 3752 KB |
1
|
3
|
|
01-05.txt | AC | 14 ms | 3592 KB |
1
|
3
|
|
01-06.txt | AC | 17 ms | 3524 KB |
1
|
3
|
|
01-07.txt | AC | 20 ms | 3560 KB |
1
|
3
|
|
01-08.txt | AC | 15 ms | 3704 KB |
1
|
3
|
|
01-09.txt | AC | 13 ms | 3808 KB |
1
|
3
|
|
01-10.txt | AC | 18 ms | 3808 KB |
1
|
3
|
|
01-11.txt | AC | 14 ms | 3552 KB |
1
|
3
|
|
01-12.txt | AC | 14 ms | 3848 KB |
1
|
3
|
|
01-13.txt | AC | 14 ms | 3828 KB |
1
|
3
|
|
01-14.txt | AC | 16 ms | 3680 KB |
1
|
3
|
|
01-15.txt | AC | 14 ms | 3796 KB |
1
|
3
|
|
01-16.txt | AC | 14 ms | 3680 KB |
1
|
3
|
|
01-17.txt | AC | 12 ms | 3668 KB |
1
|
3
|
|
01-18.txt | AC | 11 ms | 3692 KB |
1
|
3
|
|
01-19.txt | AC | 14 ms | 3684 KB |
1
|
3
|
|
01-20.txt | AC | 13 ms | 3692 KB |
1
|
3
|
|
02-01.txt | AC | 322 ms | 20124 KB |
2
|
3
|
|
02-02.txt | AC | 233 ms | 21624 KB |
2
|
3
|
|
02-03.txt | AC | 167 ms | 11792 KB |
2
|
3
|
|
02-04.txt | AC | 256 ms | 22212 KB |
2
|
3
|
|
02-05.txt | AC | 212 ms | 20968 KB |
2
|
3
|
|
02-06.txt | AC | 22 ms | 4616 KB |
2
|
3
|
|
02-07.txt | AC | 270 ms | 19956 KB |
2
|
3
|
|
02-08.txt | AC | 270 ms | 18176 KB |
2
|
3
|
|
02-09.txt | AC | 274 ms | 19500 KB |
2
|
3
|
|
02-10.txt | AC | 211 ms | 15316 KB |
2
|
3
|
|
02-11.txt | AC | 35 ms | 5496 KB |
2
|
3
|
|
02-12.txt | AC | 172 ms | 14736 KB |
2
|
3
|
|
02-13.txt | AC | 83 ms | 12672 KB |
2
|
3
|
|
02-14.txt | AC | 272 ms | 20064 KB |
2
|
3
|
|
02-15.txt | AC | 19 ms | 4188 KB |
2
|
3
|
|
02-16.txt | AC | 200 ms | 21236 KB |
2
|
3
|
|
02-17.txt | AC | 42 ms | 4988 KB |
2
|
3
|
|
02-18.txt | AC | 43 ms | 5072 KB |
2
|
3
|
|
02-19.txt | AC | 124 ms | 10160 KB |
2
|
3
|
|
02-20.txt | AC | 39 ms | 5532 KB |
2
|
3
|
|
03-01.txt | AC | 274 ms | 18684 KB |
3
|
||
03-02.txt | AC | 69 ms | 6060 KB |
3
|
||
03-03.txt | AC | 205 ms | 17676 KB |
3
|
||
03-04.txt | AC | 113 ms | 10156 KB |
3
|
||
03-05.txt | AC | 219 ms | 19920 KB |
3
|
||
03-06.txt | AC | 33 ms | 4600 KB |
3
|
||
03-07.txt | AC | 247 ms | 17172 KB |
3
|
||
03-08.txt | AC | 295 ms | 21552 KB |
3
|
||
03-09.txt | AC | 209 ms | 17272 KB |
3
|
||
03-10.txt | AC | 232 ms | 21108 KB |
3
|
||
03-11.txt | AC | 54 ms | 5808 KB |
3
|
||
03-12.txt | AC | 261 ms | 20740 KB |
3
|
||
03-13.txt | AC | 281 ms | 19928 KB |
3
|
||
03-14.txt | AC | 269 ms | 19820 KB |
3
|
||
03-15.txt | AC | 259 ms | 19824 KB |
3
|
||
03-16.txt | AC | 279 ms | 21608 KB |
3
|
||
03-17.txt | AC | 75 ms | 7008 KB |
3
|
||
03-18.txt | AC | 17 ms | 4160 KB |
3
|
||
03-19.txt | AC | 276 ms | 19972 KB |
3
|
||
03-20.txt | AC | 76 ms | 6808 KB |
3
|
||
sample-01.txt | AC | 12 ms | 3976 KB | |||
sample-02.txt | AC | 18 ms | 3896 KB | |||
sample-03.txt | AC | 12 ms | 3944 KB |