Submission #4033863


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

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

template<typename T>
struct edge {
    int src, to;
    T cost;

    // to, costで初期化
    edge (int to, T cost) : src(-1), to(to), cost(cost) {}

    // src, to, costで初期化
    edge (int src, int to, T cost) : src(src), to(to), cost(cost) {}

    // toにxを代入?
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    
    // edge()でtoを返す?
    operator int() const {return to;}
};

// templates
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<Edges<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/*
 * Dijkstra
 * input: WeightedGraph<T> &g: グラフ
 *        int s: 始点
 * output: vector<T>: sから各要素への最短経路長
 */
template<typename T>
vector<T> dijkstra(WeightedGraph<T> &g, int s) {
    const auto INF = numeric_limits<T>::max();
    vector<T> dist(g.size(), INF);

    using Pi = pair<T, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        T cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : g[idx]) {
            auto next_cost = cost + e.cost;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

double distance(double x1, double y1, double x2, double y2) {
  return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  double xs, ys, xt, yt; int n;
  cin >> xs >> ys >> xt >> yt >> n;
  vector<double> x(n), y(n), r(n);
  REP(i, n) {
    cin >> x[i] >> y[i] >> r[i];
  }
  x.pb(xs); y.pb(ys); r.pb(0);
  x.pb(xt); y.pb(yt); r.pb(0);

  WeightedGraph<double> graph(n+2);
  REP(i, n+2) {
    REP(j, n+2) {
      if(i != j) {
        edge<double> e(j, max(0.0, distance(x[i], y[i], x[j], y[j]) - r[i] - r[j]));
        graph[i].pb(e);
      }
    }
  }

  vector<double> dist = dijkstra(graph, n);
  cout << dist[n+1] << endl;
}

Submission Info

Submission Time
Task E - Cosmic Rays
User kanra824
Language C++14 (GCC 5.4.1)
Score 600
Code Size 3164 Byte
Status AC
Exec Time 108 ms
Memory 22524 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 49
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 2 ms 384 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 25 ms 16520 KB
1_03.txt AC 25 ms 16904 KB
1_04.txt AC 23 ms 16512 KB
1_05.txt AC 25 ms 16892 KB
1_06.txt AC 22 ms 16256 KB
1_07.txt AC 22 ms 16384 KB
1_08.txt AC 25 ms 16904 KB
1_09.txt AC 25 ms 16640 KB
1_10.txt AC 23 ms 16640 KB
1_11.txt AC 24 ms 16512 KB
1_12.txt AC 24 ms 16764 KB
1_13.txt AC 22 ms 16384 KB
1_14.txt AC 26 ms 17032 KB
1_15.txt AC 26 ms 17032 KB
1_16.txt AC 24 ms 16768 KB
1_17.txt AC 26 ms 16892 KB
1_18.txt AC 25 ms 16764 KB
1_19.txt AC 26 ms 17032 KB
1_20.txt AC 22 ms 16384 KB
1_21.txt AC 23 ms 16512 KB
1_22.txt AC 26 ms 16892 KB
1_23.txt AC 25 ms 16892 KB
1_24.txt AC 26 ms 17032 KB
1_25.txt AC 24 ms 16640 KB
1_26.txt AC 26 ms 16892 KB
1_27.txt AC 25 ms 16648 KB
1_28.txt AC 26 ms 16892 KB
1_29.txt AC 25 ms 17032 KB
1_30.txt AC 22 ms 16384 KB
1_31.txt AC 22 ms 16512 KB
1_32.txt AC 25 ms 17032 KB
1_33.txt AC 25 ms 16512 KB
1_34.txt AC 21 ms 16128 KB
1_35.txt AC 22 ms 16384 KB
1_36.txt AC 22 ms 16384 KB
1_37.txt AC 21 ms 16256 KB
1_38.txt AC 106 ms 20604 KB
1_39.txt AC 106 ms 21884 KB
1_40.txt AC 105 ms 22396 KB
1_41.txt AC 108 ms 22524 KB
1_42.txt AC 24 ms 16776 KB
1_43.txt AC 26 ms 17032 KB
1_44.txt AC 25 ms 17032 KB
1_45.txt AC 29 ms 17400 KB