結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2015-04-07 06:54:49 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 91 ms / 2,000 ms |
コード長 | 2,229 bytes |
コンパイル時間 | 1,617 ms |
コンパイル使用メモリ | 168,756 KB |
実行使用メモリ | 11,612 KB |
最終ジャッジ日時 | 2024-12-24 07:07:57 |
合計ジャッジ時間 | 3,136 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h>#define mp make_pair#define mt make_tuple#define pb push_back#define rep(i, n) for (int i = 0; i < (n); i++)using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> pii;typedef pair<long, long> pll;const int INF = 1 << 29;const double EPS = 1e-9;const int MOD = 100000007;const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};ll square(ll x) { return x * x; }int N;const int MAXN = 1010;ll X[MAXN], Y[MAXN];struct State {int src, tar;ll cost;State(int _src, int _tar, ll _cost) {src = _src;tar = _tar;cost = _cost;}bool operator<(const State &st) const { return cost > st.cost; }};ll check(ll n) {ll low = 0;ll high = 1LL << 32;while (high - low > 1) {ll med = (high + low) / 2;if (med * med <= n)low = med;elsehigh = med;}return low;}//Union Findstruct UnionFind {vector<int> par;vector<int> rank;UnionFind(int n) {par.resize(n);rank.resize(n, 0);for (int i = 0; i < n; i++) {par[i] = i;}}void unit(int x, int y) {int X = find(x);int Y = find(y);if (X == Y)return;if (rank[X] < rank[Y]) {par[X] = Y;} else {par[Y] = X;if (rank[X] == rank[Y]) {rank[X]++;}}}bool same(int x, int y) { return find(x) == find(y); }int find(int x) {if (par[x] == x) {return x;} else {return par[x] = find(par[x]);}}};int main() {cin >> N;for (int i = 0; i < N; i++) {cin >> X[i] >> Y[i];}priority_queue<State> que;for (int i = 0; i < N; i++) {for (int j = i + 1; j < N; j++) {ll dist = check(square(X[i] - X[j]) + square(Y[i] - Y[j]));if (dist * dist < square(X[i] - X[j]) + square(Y[i] - Y[j])) {dist++;}if (dist % 10 == 0) {que.push(State(i, j, dist));} else {que.push(State(i, j, (dist / 10 + 1) * 10));}}}UnionFind uf(N);ll res = 0;while (1){if (uf.same(0, N - 1))break;State pos = que.top();que.pop();res = pos.cost;uf.unit(pos.src, pos.tar);}cout << res << endl;return 0;}