結果
| 問題 |
No.168 ものさし
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-21 09:58:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 91 ms / 2,000 ms |
| コード長 | 1,362 bytes |
| コンパイル時間 | 1,043 ms |
| コンパイル使用メモリ | 99,540 KB |
| 実行使用メモリ | 11,264 KB |
| 最終ジャッジ日時 | 2024-07-21 22:47:19 |
| 合計ジャッジ時間 | 2,234 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cassert>
#include <cmath>
#include <bitset>
using namespace std;
class UnionFind {
private:
vector<int> par;
public:
UnionFind(int N) {
par.resize(N);
iota(par.begin(), par.end(), 0);
}
int root(int x) {
return par[x] == x ? x : par[x] = root(par[x]);
}
bool same(int x, int y) {
return root(x) == root(y);
}
void unite(int x, int y) {
if (same(x, y)) return;
x = root(x);
y = root(y);
par[y] = x;
}
};
int main() {
int n;
cin >> n;
vector<long long> x(n), y(n);
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
vector<vector<long long>> d2(n, vector<long long>(n));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
d2[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
//printf("d2[%d][%d] = %lld\n", i, j, d2[i][j]);
}
long long ok = (long long)3e9;
long long ng = 0;
while (ng + 1 < ok) {
long long x = (ok+ng)/2;
UnionFind uf(n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (x*x >= d2[i][j]) uf.unite(i, j);
if (uf.same(0, n-1)) ok = x;
else ng = x;
}
cout << (ok+9) / 10 * 10 << endl;
}