Submission #2868296


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


const ll INF = LLONG_MAX;

typedef long double LD;



void dij1(int nV, vector<vector<LD>>& table, vector<LD>& d, int start) {
	// nV: |V|
	d.assign(nV, INF);
	d[start] = 0;
	vector<int> prev(nV, -1);

	priority_queue<pair<LD, int>> Q;
	Q.push(make_pair(0, start));

	vector<bool> visited(nV, false);

	while (!Q.empty()) {
		LD du = -Q.top().first;
		int u = Q.top().second; Q.pop();
		if (visited[u]) continue;
		visited[u] = true;

        rep(v, nV) {
            if (v == u) continue;
			LD alt = du + table[u][v];
			if (d[v] > alt) {
				d[v] = alt;
				prev[v] = u;
				Q.push(make_pair(-alt, v));
			}
		}
	}
}


int N;
vector<int> x,y,r;

LD distance(int i, int j) {
    int dx = abs(x[i] - x[j]), dy = abs(y[i] - y[j]);
    int rsum = r[i] + r[j];
    LD d = hypotl(dx, dy);
    if (d <= rsum) return 0;
    else return d - rsum;
}

LD solve() {
#ifdef DEBUG
    cerr << "N:" << N << endl;
    cerr << "x:" << x << endl;
    cerr << "y:" << y << endl;
    cerr << "r:" << r << endl;
#endif
    vector<vector<LD>> table(N, vector<LD>(N, INF));
    rep(i,N) table[i][i] = 0;
    repC2(i,j,N) table[i][j] = table[j][i] = distance(i, j);

    vector<LD> d(N, INF);
    dij1(N, table, d, 0);
#ifdef DEBUG
    cerr << d << endl;
#endif
    return d[1];
}

int main() {
    int xs,ys,xt,yt; cin >> xs >> ys >> xt >> yt;
    cin >> N;
    x.resize(N+2);
    y.resize(N+2);
    r.resize(N+2);
    x[0] = xs; y[0] = ys; r[0] = 0;
    x[1] = xt; y[1] = yt; r[1] = 0;
    rep(i,N){
        cin >> x[2+i] >> y[2+i] >> r[2+i];
    }
    N += 2;
    printf("%.10Lf\n", solve());
    return 0;
}

Submission Info

Submission Time
Task E - Cosmic Rays
User naoya_t
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2891 Byte
Status
Exec Time 167 ms
Memory 26092 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt
All 600 / 600 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 3 ms 384 KB
0_01.txt 1 ms 256 KB
0_02.txt 1 ms 256 KB
1_00.txt 1 ms 256 KB
1_01.txt 1 ms 256 KB
1_02.txt 46 ms 16632 KB
1_03.txt 47 ms 16888 KB
1_04.txt 45 ms 16252 KB
1_05.txt 46 ms 17020 KB
1_06.txt 44 ms 15744 KB
1_07.txt 43 ms 16000 KB
1_08.txt 46 ms 16888 KB
1_09.txt 46 ms 16512 KB
1_10.txt 44 ms 16384 KB
1_11.txt 45 ms 16252 KB
1_12.txt 44 ms 16128 KB
1_13.txt 46 ms 16128 KB
1_14.txt 48 ms 17144 KB
1_15.txt 49 ms 17144 KB
1_16.txt 47 ms 16636 KB
1_17.txt 48 ms 17020 KB
1_18.txt 49 ms 16760 KB
1_19.txt 50 ms 17144 KB
1_20.txt 44 ms 16128 KB
1_21.txt 44 ms 16124 KB
1_22.txt 48 ms 17020 KB
1_23.txt 47 ms 17020 KB
1_24.txt 49 ms 17144 KB
1_25.txt 46 ms 16380 KB
1_26.txt 49 ms 16888 KB
1_27.txt 46 ms 16504 KB
1_28.txt 55 ms 17020 KB
1_29.txt 48 ms 17144 KB
1_30.txt 43 ms 16000 KB
1_31.txt 44 ms 16256 KB
1_32.txt 46 ms 16636 KB
1_33.txt 46 ms 16128 KB
1_34.txt 41 ms 15488 KB
1_35.txt 42 ms 16000 KB
1_36.txt 42 ms 16000 KB
1_37.txt 41 ms 15744 KB
1_38.txt 167 ms 26092 KB
1_39.txt 167 ms 25452 KB
1_40.txt 164 ms 25708 KB
1_41.txt 167 ms 24940 KB
1_42.txt 43 ms 16124 KB
1_43.txt 46 ms 17144 KB
1_44.txt 45 ms 17144 KB
1_45.txt 48 ms 18040 KB