Submission #8829113
Source Code Expand
/* 貪欲 後ろから見る DP 順位表をチェック 二分探索 */ #pragma GCC optimize("Ofast") #include<cstdio> #include<cstdlib> #include<algorithm> #include<iostream> #include<queue> #include<vector> #include <bitset> #include <cmath> #include <limits> #include <iostream> #include <map> #include<tuple> using namespace std; #define INF 3e18+7 #define MAX 100000 #define MOD 1000000007 typedef long long ll; typedef pair<double,int> P; //typedef pair<pair<int,int>,int> p; #define bit(n,k) ((n>>k)&1) /*nのk bit目*/ #define rad_to_deg(rad) (((rad)/2/M_PI)*360) struct edge{ll to,cost,val;}; template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;} template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;} //__builtin_popcount(S); //C.erase(unique(C.begin(),C.end()),C.end()); int S[110000],Z[110000]; int C[1100]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll sx,sy,tx,ty,x[1100],y[1100],r[1100]; double d[1100]; cin>>sx>>sy>>tx>>ty>>N; vector<P> V; for(int i=1;i<=N;i++){ cin>>x[i]>>y[i]>>r[i]; double t=sqrt((sx-x[i])*(sx-x[i])+(sy-y[i])*(sy-y[i])); t-=(r[i]); if(t<0) t=0; d[i]=t; V.push_back(P(t,i)); //cout<<d[i]<<endl; } sort(V.begin(),V.end()); int n; for(int i=0;i<=N-1;i++){ int s; if(i==0) s=V[i].second; else s=n; double m=INF; C[n]++; for(int j=1;j<=N;j++){ if(C[j]) continue; int next=j; double t=sqrt( (x[s]-x[next])*(x[s]-x[next])+(y[s]-y[next])*(y[s]-y[next]) ); t-=(r[s]+r[next]); if(t<0) t=0; chmin(d[next],d[s]+t); if(m>d[next]){ m=d[next]; n=next; } } } double ans=sqrt( (sx-tx)*(sx-tx)+(sy-ty)*(sy-ty) ); for(int i=1;i<=N;i++){ double t=sqrt( (x[i]-tx)*(x[i]-tx)+(y[i]-ty)*(y[i]-ty) ); t-=r[i]; if(t<0) t=0; chmin(ans,d[i]+t); } printf("%.15lf\n",ans); }
Submission Info
Submission Time | |
---|---|
Task | E - Cosmic Rays |
User | bin101 |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 2215 Byte |
Status | AC |
Exec Time | 5 ms |
Memory | 384 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 | 5 ms | 384 KB |
1_03.txt | AC | 5 ms | 384 KB |
1_04.txt | AC | 4 ms | 384 KB |
1_05.txt | AC | 5 ms | 384 KB |
1_06.txt | AC | 4 ms | 384 KB |
1_07.txt | AC | 4 ms | 384 KB |
1_08.txt | AC | 5 ms | 384 KB |
1_09.txt | AC | 5 ms | 384 KB |
1_10.txt | AC | 4 ms | 384 KB |
1_11.txt | AC | 5 ms | 384 KB |
1_12.txt | AC | 5 ms | 384 KB |
1_13.txt | AC | 4 ms | 384 KB |
1_14.txt | AC | 5 ms | 384 KB |
1_15.txt | AC | 5 ms | 384 KB |
1_16.txt | AC | 5 ms | 384 KB |
1_17.txt | AC | 5 ms | 384 KB |
1_18.txt | AC | 5 ms | 384 KB |
1_19.txt | AC | 5 ms | 384 KB |
1_20.txt | AC | 4 ms | 384 KB |
1_21.txt | AC | 5 ms | 384 KB |
1_22.txt | AC | 5 ms | 384 KB |
1_23.txt | AC | 5 ms | 384 KB |
1_24.txt | AC | 5 ms | 384 KB |
1_25.txt | AC | 5 ms | 384 KB |
1_26.txt | AC | 5 ms | 384 KB |
1_27.txt | AC | 5 ms | 384 KB |
1_28.txt | AC | 5 ms | 384 KB |
1_29.txt | AC | 5 ms | 384 KB |
1_30.txt | AC | 4 ms | 384 KB |
1_31.txt | AC | 4 ms | 384 KB |
1_32.txt | AC | 5 ms | 384 KB |
1_33.txt | AC | 5 ms | 384 KB |
1_34.txt | AC | 4 ms | 384 KB |
1_35.txt | AC | 5 ms | 384 KB |
1_36.txt | AC | 5 ms | 384 KB |
1_37.txt | AC | 5 ms | 384 KB |
1_38.txt | AC | 5 ms | 384 KB |
1_39.txt | AC | 5 ms | 384 KB |
1_40.txt | AC | 5 ms | 384 KB |
1_41.txt | AC | 5 ms | 384 KB |
1_42.txt | AC | 4 ms | 384 KB |
1_43.txt | AC | 4 ms | 384 KB |
1_44.txt | AC | 4 ms | 384 KB |
1_45.txt | AC | 4 ms | 384 KB |