結果
| 問題 |
No.94 圏外です。(EASY)
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2024-07-13 00:53:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 5,000 ms |
| コード長 | 2,713 bytes |
| コンパイル時間 | 2,008 ms |
| コンパイル使用メモリ | 152,280 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-13 00:53:59 |
| 合計ジャッジ時間 | 3,655 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
#include<iomanip>
#include<math.h>
ll cross(ll a,ll b,ll c,ll d){
return a * d - b * c;
}
int ccw(pair<ll,ll> a,pair<ll,ll> b,pair<ll,ll> c) {
ll dx = b.first - a.first;
ll dy = b.second - a.second;
ll ddx = c.first - b.first;
ll ddy = c.second - b.second;
ll now = cross(dx,dy,ddx,ddy);
if(now<0) return -1;
if(now>0) return 1;
return 0;
}
long double calc(vector<pair<ll,ll>> use) {
int n = use.size();
sort(use.begin(),use.end());
if(n==1) return 2;
vector<pair<ll,ll>> upper,lower;
for(int i = 0;i<n;i++){
while(upper.size()>=2){
int m = upper.size();
if(ccw(upper[m-2],upper[m-1],use[i])!=-1) upper.pop_back();
else break;
}
upper.push_back(use[i]);
}
for(int i = 0;i<n;i++){
while(lower.size()>=2){
int m = lower.size();
if(ccw(lower[m-2],lower[m-1],use[i])!=1) lower.pop_back();
else break;
}
lower.push_back(use[i]);
}
long double ans = 0;
reverse(lower.begin(),lower.end());
for(int i = 1;i+1<lower.size();i++) upper.push_back(lower[i]);
int ni = 0;
int m = upper.size();
auto d = [&](int i,int j) -> long double {
ll dx = upper[i].first - upper[j].first;
ll dy = upper[i].second - upper[j].second;
return sqrt(dx*dx+dy*dy);
};
for(int i = 0;i<m;i++){
while(true){
ans = max(ans,d(i,ni));
int nj = ni + 1;
if(nj==m) nj = 0;
if(d(i,nj)>d(i,ni)) ni = nj;
else break;
}
ans = max(d(i,ni),ans);
}
return ans + 2;
}
#include<atcoder/dsu>
#include<map>
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<ll> x(n),y(n);
for(int i = 0;i<n;i++) cin>>x[i]>>y[i];
atcoder::dsu uf(n);
map<pair<ll,ll>,int> memo;
for(int i = 0;i<n;i++) memo[make_pair(x[i],y[i])] = i;
long double ans = 1;
for(int i = 0;i<n;i++){
for(int ni = -10;ni<=10;ni++){
for(int nj = -10;nj<=10;nj++){
ll now = ni * ni + nj * nj;
if(now>100) continue;
pair<ll,ll> want = make_pair(x[i]+ni,y[i]+nj);
if(memo.find(want)!=memo.end()) {
uf.merge(i,memo[want]);
}
}
}
}
for(auto&now:uf.groups()){
vector<pair<ll,ll>> use;
for(int i:now) use.push_back(make_pair(x[i],y[i]));
ans = max(ans,calc(use));
}
cout<<setprecision(30)<<fixed<<ans<<endl;
}
momoyuu