結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2018-08-31 18:08:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 115 ms / 2,000 ms |
コード長 | 1,606 bytes |
コンパイル時間 | 1,475 ms |
コンパイル使用メモリ | 72,380 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-09-13 22:40:31 |
合計ジャッジ時間 | 2,273 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>#include <iomanip>using namespace std;typedef long long ll;typedef pair<int, int> P;const int INF = (int)1e9 + 1;int n;ll x[1010], y[1010];ll d[1010][1010];class DisjointSet {public:vector<int> rank, p;DisjointSet() {}DisjointSet(int size) {rank.resize(size, 0);p.resize(size, 0);for (int i = 0; i < size; i++) {makeSet(i);}}void makeSet(int x) {p[x] = x;rank[x] = 0;}bool same(int x, int y) {return findSet(x) == findSet(y);}void unite(int x, int y) {link(findSet(x), findSet(y));}void link(int x, int y) {if (rank[x] > rank[y]) {p[y] = x;}else {p[x] = y;if (rank[x] == rank[y]) {rank[y]++;}}}int findSet(int x) {if (x != p[x]) {p[x] = findSet(p[x]);}return p[x];}};bool solve(ll len) {DisjointSet ds = DisjointSet(n);for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if (d[i][j] <= len * len) {ds.unite(i, j);}}}return ds.same(0, n - 1);}int main(void) {cin >> n;for (int i = 0; i < n; i++) {cin >> x[i] >> y[i];}for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {d[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);}}ll left = 0LL, right = 1e10;while (right - left > 1) {ll mid = (left + right) / 2;if (solve(mid)) {right = mid;}else {left = mid;}}ll ans = left;for (int i = 0; i <= 11; i++) {if (ans % 10 == 0) {if (solve(ans)) break;}ans++;}cout << ans << '\n';return 0;}