結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2019-10-23 23:10:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 2,195 bytes |
コンパイル時間 | 1,031 ms |
コンパイル使用メモリ | 112,600 KB |
実行使用メモリ | 36,352 KB |
最終ジャッジ日時 | 2024-07-07 06:25:12 |
合計ジャッジ時間 | 2,588 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#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;}