結果
| 問題 |
No.168 ものさし
|
| コンテスト | |
| ユーザー |
🍡yurahuna
|
| 提出日時 | 2016-02-25 11:30:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 2,071 bytes |
| コンパイル時間 | 736 ms |
| コンパイル使用メモリ | 83,068 KB |
| 実行使用メモリ | 19,808 KB |
| 最終ジャッジ日時 | 2024-12-24 07:12:35 |
| 合計ジャッジ時間 | 2,477 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define PI 3.1415926535
typedef long long ll;
//typedef pair<int, int> P;
//typedef complex<double> C;
struct edge {
int from, to;
ll cost;
edge() {}
edge(int f, int t, ll c) {
from = f; to = t; cost = c;
}
};
bool cmp (const edge& e1, const edge& e2) {
return e1.cost < e2.cost;
}
const int MAX_N = 1000;
int N;
ll X[MAX_N], Y[MAX_N];
vector<edge> es;
int uni[MAX_N];
void input() {
cin >> N;
REP(i, N) cin >> X[i] >> Y[i];
}
ll hyp(int i, int j) {
return (X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]);
}
void initEdge() {
REP(i, N) {
FOR(j, i + 1, N) {
ll dist = (ll)sqrt(hyp(i, j));
ll cost = dist - dist % 10; // 辺(i, j)を書くのに必要なものさしの長さ
while (cost * cost < hyp(i, j)) cost += 10;
es.pb(edge(i, j, cost));
es.pb(edge(j, i, cost));
}
}
}
void initUf(int n) {
REP(i, n) uni[i] = -1;
}
int root(int x) {
if (uni[x] < 0) return x;
return uni[x] = root(uni[x]);
}
bool same(int x, int y) {
return root(x) == root(y);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return;
if (uni[x] > uni[y]) swap(x, y);
uni[x] += uni[y];
uni[y] = x;
}
void solve() {
initEdge();
sort(ALL(es), cmp);
initUf(N);
REP(i, es.size()) {
edge e = es[i];
if (!same(e.from, e.to)) {
unite(e.from, e.to);
}
if (same(0, N - 1)) {
cout << e.cost << endl;
return;
}
}
}
int main() {
input();
solve();
return 0;
}
🍡yurahuna