結果

問題 No.168 ものさし
ユーザー mayoko_
提出日時 2015-03-20 00:01:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,125 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 81,992 KB
実行使用メモリ 11,616 KB
最終ジャッジ日時 2024-12-24 06:56:19
合計ジャッジ時間 2,153 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long ll;
const int MAXN = 1024;
ll X[MAXN], Y[MAXN];
const ll INF = 1ll<<63;
ll square(ll x) {return x*x;}
ll lsqrt(ll n) {
ll low = 0, high = 1ll<<31;
while (high - low > 1) {
ll med = (high + low) / 2;
if (med * med <= n) low = med;
else high = med;
}
return low;
}
// unionFind
const int UNION_MAX = 1024;
class unionFind {
int par[UNION_MAX];
int Rank[UNION_MAX];
public:
void init(int nn) {
for (int i = 0; i <= nn; i++) {
par[i] = i;
Rank[i] = 0;
}
}
int find(int x) {
if (x == par[x]) return x;
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x); 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);
}
};
unionFind uf;
int main(void) {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> X[i] >> Y[i];
}
priority_queue<pair<ll, pair<int, int> > > que;
for (int i = 0; i < N; i++) {
for (int j = i+1; j < N; j++) {
ll dist = lsqrt(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(make_pair(-dist/10*10, make_pair(i, j)));
else que.push(make_pair(-(dist/10+1)*10, make_pair(i, j)));
}
}
uf.init(N);
ll ret = 10;
while (1) {
if (uf.same(0, N-1)) break;
auto now = que.top(); que.pop();
ret = -now.first;
uf.unite(now.second.first, now.second.second);
}
cout << ret << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0