Submission #4592926
Source Code Expand
#include<iostream> #include<vector> #include<algorithm> #include<utility> #include<string> #include<cmath> #include<cstring> #include<queue> #include<map> #include<climits> #include<set> using namespace std; typedef pair<int, int> pii; typedef long long int ll; typedef pair<ll, ll> pll; int dx[4] = { 1,0,0,-1 }; int dy[4] = { 0,1,-1,0 }; #define MOD 1000000007 #define ARRAY_MAX 100005 const double INF = 1e15 + 7; typedef pair<ll, double> plld; typedef struct edge { int to; double cost; }EDGE; void dijkstra(int n, vector<vector<EDGE> >& G, int x,vector<double>& d) { /*頂点の個数、辺の情報、始点となる頂点、最短距離の情報*/ /*最終的にdは経由点からの最短距離が格納される、その過程では暫定的な最短距離が格納され、最短距離が見つかれば、その都度更新される*/ //vector<ll> d(n,INF);/*最終的な最短距離を保持、初期化はINF*/ d[x] = 0; priority_queue<plld, vector<plld>, greater<plld> > que;/*vectorのpriority_queueで暫定的な最短距離が小さい順に取り出す*/ que.push(plld(0, x));/*経由点からダイクストラを適用するので経由点の暫定的な最短距離のコストは0*/ while (!que.empty()) {/*queが空になれば最短距離が全て探索できたことになる*/ plld p = que.top();/*最短距離の1番小さいものの取り出し*/ que.pop();/*取り出したので調べたとみなし、queから出す*/ int v = p.second;/*取り出した頂点の番号*/ if (d[v] < p.first) { /*取り出した頂点からの最短距離よりも短い経路があるので更新の必要はない*/ continue; } for (int i = 0; i < G[v].size(); i++) { /*取り出した頂点から辺でつながっている頂点への最短距離を調べて現在の値より短ければ更新する*/ EDGE e = G[v][i];/*取り出した頂点からつながっている頂点を1つ取り出す*/ if (d[e.to] > d[v] + e.cost) { /*現在の最短距離よりも、現在の頂点を経由する経路のほうが最短距離が短い場合は最短距離を更新し、次の頂点を調べる*/ d[e.to] = d[v] + e.cost;/*最短経路の更新*/ que.push(plld(d[e.to], e.to));/*先の頂点を調べるためqueに格納*/ } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); double xs, ys, xt, yt; int n; cin >> xs >> ys >> xt >> yt >> n; vector<vector<EDGE> > G(n+2);/*n個の各頂点からそれ以外の頂点へのコスト*/ vector<double> d(n+2, INF);/*最短経路*/ vector<double> x(n + 2), y(n + 2), r(n + 2);//(x,y),半径 x[0] = xs; y[0] = ys; r[0] = 0; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i] >> r[i]; } x[n+1] = xt; y[n+1] = yt; r[n+1] = 0; for (int i = 0; i <= n + 1; i++) { for (int j = i + 1; j <= n + 1; j++) { double len = sqrt((x[j] - x[i])*(x[j] - x[i]) + (y[j] - y[i])*(y[j] - y[i])); double radius = r[i] + r[j]; double dis = max(0.0,len - radius); G[i].push_back(EDGE{ j,dis }); G[j].push_back(EDGE{ i,dis }); } } dijkstra(n, G, 0, d); printf("%.12f\n", d[n + 1]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Cosmic Rays |
User | punipuni |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 3278 Byte |
Status | AC |
Exec Time | 104 ms |
Memory | 22000 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 1 ms | 256 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | AC | 1 ms | 256 KB |
1_02.txt | AC | 26 ms | 16640 KB |
1_03.txt | AC | 27 ms | 17020 KB |
1_04.txt | AC | 24 ms | 16768 KB |
1_05.txt | AC | 26 ms | 17020 KB |
1_06.txt | AC | 24 ms | 16512 KB |
1_07.txt | AC | 24 ms | 16512 KB |
1_08.txt | AC | 26 ms | 17020 KB |
1_09.txt | AC | 26 ms | 16896 KB |
1_10.txt | AC | 25 ms | 16768 KB |
1_11.txt | AC | 26 ms | 16656 KB |
1_12.txt | AC | 26 ms | 16892 KB |
1_13.txt | AC | 24 ms | 16640 KB |
1_14.txt | AC | 27 ms | 17148 KB |
1_15.txt | AC | 28 ms | 17148 KB |
1_16.txt | AC | 26 ms | 16896 KB |
1_17.txt | AC | 28 ms | 17020 KB |
1_18.txt | AC | 27 ms | 17040 KB |
1_19.txt | AC | 28 ms | 17148 KB |
1_20.txt | AC | 24 ms | 16512 KB |
1_21.txt | AC | 24 ms | 16640 KB |
1_22.txt | AC | 28 ms | 17020 KB |
1_23.txt | AC | 28 ms | 17148 KB |
1_24.txt | AC | 27 ms | 17148 KB |
1_25.txt | AC | 26 ms | 16768 KB |
1_26.txt | AC | 28 ms | 17020 KB |
1_27.txt | AC | 26 ms | 16892 KB |
1_28.txt | AC | 27 ms | 17168 KB |
1_29.txt | AC | 27 ms | 17184 KB |
1_30.txt | AC | 24 ms | 16512 KB |
1_31.txt | AC | 24 ms | 16640 KB |
1_32.txt | AC | 27 ms | 17148 KB |
1_33.txt | AC | 27 ms | 16640 KB |
1_34.txt | AC | 23 ms | 16256 KB |
1_35.txt | AC | 24 ms | 16512 KB |
1_36.txt | AC | 24 ms | 16512 KB |
1_37.txt | AC | 23 ms | 16384 KB |
1_38.txt | AC | 104 ms | 21488 KB |
1_39.txt | AC | 104 ms | 21360 KB |
1_40.txt | AC | 102 ms | 20976 KB |
1_41.txt | AC | 104 ms | 22000 KB |
1_42.txt | AC | 25 ms | 16892 KB |
1_43.txt | AC | 28 ms | 17148 KB |
1_44.txt | AC | 26 ms | 17184 KB |
1_45.txt | AC | 31 ms | 17656 KB |