結果
| 問題 |
No.168 ものさし
|
| コンテスト | |
| ユーザー |
oxyshower
|
| 提出日時 | 2019-04-10 12:40:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,811 bytes |
| コンパイル時間 | 1,968 ms |
| コンパイル使用メモリ | 177,868 KB |
| 実行使用メモリ | 15,740 KB |
| 最終ジャッジ日時 | 2024-07-06 21:54:38 |
| 合計ジャッジ時間 | 3,049 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 14 WA * 5 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct edge{ int u,v,cost; };
bool comp(const edge& e1,const edge& e2){
return e1.cost < e2.cost;
}
vector<edge> es;
int V,E; //頂点数、辺数
const int N = 1e5+10;
struct UF{
vector<int> par; //親
vector<int> size; //集合の大きさ
void init(int n){
par.resize(n);
size.resize(n);
for(int i = 0; i < n; i++){
par[i] = i;
size[i] = 1;
}
}
//木の根を求める
int root(int x){
if(par[x] == x){
return x;
}
else {
return par[x] = root(par[x]);
}
}
//xとyの属する集合を併合
void unite(int x,int y){
x = root(x);
y = root(y);
if(x == y) return;
if(size[x] < size[y]) swap(x,y);
par[y] = x;
size[x] += size[y];
}
}uf;
int kruskal(int ok){
//sort(es.begin(),es.end(),comp);
uf.init(V);
int total = 0;
for(int i = 0; i < es.size(); i++){
edge e = es[i];
if(e.cost > ok) break;
if(uf.root(e.u) != uf.root(e.v)){
total += e.cost;
uf.unite(e.u,e.v);
}
}
return uf.root(0) == uf.root(V-1);
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> V;
vector<int> x(V),y(V);
for(int i = 0; i < V; i++){
cin >> x[i] >> y[i];
}
for(int i = 0; i < V; i++){
for(int j = i+1; j < V; j++){
int cost = abs(x[i] - x[j])*abs(x[i] - x[j]) + abs(y[i] - y[j])*abs(y[i] - y[j]);
es.push_back({i,j,cost});
}
}
sort(es.begin(),es.end(),comp);
function< int(int) > check =
[&](int mid){
if(kruskal(mid*mid)) return 1LL;
return 0LL;
};
int ok = -1, ng = 1e9+10;
while(ng - ok > 1){
int mid = (ok + ng) / 2;
if(!check(mid)) ok = mid;
else ng = mid;
}
while(ok%10 != 0) ok++;
cout << ok << endl;
return 0;
}
oxyshower