結果

問題 No.168 ものさし
ユーザー kakakakaneko
提出日時 2018-04-12 22:54:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,790 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 106,348 KB
実行使用メモリ 16,796 KB
最終ジャッジ日時 2024-06-26 21:35:57
合計ジャッジ時間 2,575 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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

#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>
using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const double INF3 = 900000000000000;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
ll par[100010], Rank[100010];
void init(int n) {
for (int i = 0;i < n;i++)par[i] = i, Rank[i] = 0;
}
int find(ll x) {
if (par[x] == x)return x;
else return par[x] = find(par[x]);
}
void unite(ll x, ll 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(ll x, ll y) {
return find(x) == find(y);
}
int main() {
ll n, x[1010], y[1010], ans = INF2;
cin >> n;
for (int i = 0;i < n;i++) {
cin >> x[i] >> y[i];
}
vector<pair<ll, P>>v;
for (int i = 0;i < n - 1;i++)for (int j = i + 1;j < n;j++) {
ll dis = (ll)sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
dis -= dis % 10;
while (dis*dis < (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]))dis += 10;
v.push_back(make_pair(dis, make_pair(i, j)));
}
sort(v.begin(), v.end());
init(1010);
for (int i = 0;i < v.size();i++) {
if (!same(v[i].second.first, v[i].second.second)) {
unite(v[i].second.first, v[i].second.second);
ans = v[i].first;
}
if (find(0) == find(n - 1))break;
}
cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0