結果

問題 No.168 ものさし
ユーザー eye_engineeye_engine
提出日時 2019-10-23 23:10:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 2,195 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 112,176 KB
実行使用メモリ 36,084 KB
最終ジャッジ日時 2023-09-21 12:36:51
合計ジャッジ時間 2,884 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
11,216 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 5 ms
4,660 KB
testcase_11 AC 26 ms
10,552 KB
testcase_12 AC 79 ms
29,268 KB
testcase_13 AC 92 ms
35,836 KB
testcase_14 AC 50 ms
35,436 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 7 ms
4,872 KB
testcase_19 AC 127 ms
35,308 KB
testcase_20 AC 106 ms
36,084 KB
testcase_21 AC 143 ms
35,988 KB
testcase_22 AC 89 ms
36,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;

struct edge {
  ll to, cost;
  edge(ll t, ll c) : to(t), cost(c) {}
};

class Dijkstra {
 private:
  ll n_;
  vector<vector<edge>> G_;
  vl d_;

 public:
  Dijkstra(ll n) : n_(n), G_(n), d_(n, INF) {}
  void addEdge(ll v, ll to, ll cost) { G_[v].push_back(edge(to, cost)); }
  void exec(ll s, ll limit) {
    d_ = vl(n_, INF);
    priority_queue<pll, vector<pll>, greater<pll>> que;
    d_[s] = 0;
    que.push({0, s});

    while (!que.empty()) {
      pll p = que.top();
      que.pop();
      ll v = p.second;
      if (d_[v] < p.first) continue;
      for (auto& e : G_[v]) {
        if (e.cost <= limit && d_[e.to] > d_[v] + e.cost) {
          d_[e.to] = d_[v] + e.cost;
          que.push({d_[e.to], e.to});
        }
      }
    }
  }
  ll dist(ll g) { return d_[g]; }
};


int main() {
  //
  ll n;
  cin >> n;
  vl x(n), y(n);
  rep(i, n) {
    cin >> x[i] >> y[i];
  }
  Dijkstra d(n);
  rep(i, n) {
    rep(j, n) {
      if (i == j) continue;
      ll dist = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
      d.addEdge(j, i, dist);
      d.addEdge(i, j, dist);
    }
  }
  ll ok = (x[n-1] - x[0]) * (x[n-1] - x[0]) + (y[n-1] - y[0]) * (y[n-1] - y[0]);
  ll ng = 0;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    d.exec(0, mid);
    if (d.dist(n - 1) == INF) {
      ng = mid;
    } else {
      ok = mid;
    }
  }
  ll ans = (ll)sqrt(ok) / 10 * 10;
  while (ans * ans < ok) ans += 10;
  cout << ans << endl;
  return 0;
}
0