結果

問題 No.96 圏外です。
ユーザー yaoshimaxyaoshimax
提出日時 2015-03-08 18:03:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 4,044 bytes
コンパイル時間 1,126 ms
コンパイル使用メモリ 108,624 KB
実行使用メモリ 814,700 KB
最終ジャッジ日時 2023-09-06 21:51:12
合計ジャッジ時間 28,163 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,368 KB
testcase_01 AC 4 ms
6,280 KB
testcase_02 AC 4 ms
6,452 KB
testcase_03 AC 4 ms
6,324 KB
testcase_04 AC 118 ms
32,712 KB
testcase_05 AC 211 ms
52,000 KB
testcase_06 WA -
testcase_07 AC 550 ms
107,776 KB
testcase_08 AC 783 ms
157,756 KB
testcase_09 WA -
testcase_10 AC 1,432 ms
245,180 KB
testcase_11 AC 1,916 ms
352,564 KB
testcase_12 WA -
testcase_13 AC 2,920 ms
428,288 KB
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

class UnionFindTree
{
   private:
      int N;
      int *rootnum;
      int *rank;
      int *unionnum;

   public:
      UnionFindTree(int n){
         /*0からn-1までの要素をunionとしてもつ*/
         N = n;
         rootnum = new int[N];
         rank = new int[N];
         unionnum = new int[N];
         for( int i = 0 ; i < N ; i++ ){
            rootnum[i] = i;
            rank[i] = 0;
            unionnum[i] = 1;
         }
      }
      
      int Find( int j ){
         if( rootnum[j] == j ){
            return j;
         }
         else{
            return rootnum[j] = Find(rootnum[j]);
         }
      }

      void Union( int i , int j ){
         int x = Find(i);
         int y = Find(j);
         if( x == y ) return;
         N--;
         if( rank[x] < rank[y] ){
            rootnum[y] = x;
            unionnum[x] += unionnum[y];
         }else{
            rootnum[x] = y;
            unionnum[y] += unionnum[x];
            if( rank[x]==rank[y] ) rank[x]++;
         }
      }

      int Num( int j ){
         /*与えられた要素の入っている集合の要素数を答える*/
         int x = Find(j);
         return unionnum[x];
      }

      int UnionNum(){
         /*集合の数を答える*/
         return N;
      }

      ~UnionFindTree(){
         delete rootnum;
         delete rank;
         delete unionnum;
      }

};

long long product( pair<int,int> p1, pair<int,int> p2, pair<int,int> p3 ){
   pair<int,int> v1 = make_pair( p2.first-p1.first, p2.second-p1.second);
   pair<int,int> v2 = make_pair( p3.first-p1.first, p3.second-p1.second);
   return v1.first*(long long)v2.second-v1.second*(long long)v2.first;
}

vector< pair<int,int> > convex_hull( vector<pair<int,int> > &V){
   sort(V.begin(),V.end());
   if( V.size() <=2 ) return V;
   int size = V.size();
   vector<pair<int,int> > ret(size*2);
   int retlen=0; 
   for( int i = 0 ; i <size; i++ ){
      while( retlen >= 2 && product( ret[retlen-2],ret[retlen-1],V[i] ) >= 0 ) retlen--;
      ret[retlen++]=V[i];
   }
   for( int i = size-1 ; i > 0 ; i-- ){
      while( retlen >= 2 && product( ret[retlen-2],ret[retlen-1],V[i] ) >= 0 ) retlen--;
      ret[retlen++]=V[i];
   }
   ret.resize(retlen);
   return ret;
}

pair<int,int> points[120001];
vector< pair<int,int > > V[120001];

int main(){
   int N;
   cin >> N;

   map< pair<int,int>, int>  m;
   UnionFindTree uft(N);

   for( int i = 0 ; i < N ; i++ ){
      V[i].clear();
      cin >> points[i].first >> points[i].second;
      m[points[i]]=i+1;
   }
   if( N == 0 ){
      printf("%.10f\n",1.0);
      return 0;
   }
   for( int i = 0 ; i < N ; i++ ){
      int x = points[i].first;
      int y = points[i].second;
      for( int x2 = x ; x2 <= x+10; x2++ ){
         for( int y2 = y-10; y2 <= y+10; y2++ ){
            if( x==x2 && y==y2) continue;
            if( (x2-x)*(x2-x)+(y2-y)*(y2-y) > 100 ) continue;
            if( m[make_pair(x2,y2)]>0){
               int ind = m[make_pair(x2,y2)];
               uft.Union(i,ind-1);
            }
         }
      }
   }
   for( int i = 0 ; i < N ; i++ ){
      V[uft.Find(i)].push_back(points[i]);
   }
   
   long long maxDist = 0;
   for( int i = 0 ; i <N; i++ ){
      vector<pair<int,int> > convPoints = convex_hull(V[i]);  
      for( int j = 0 ; j < (int) convPoints.size(); j ++ ){
         for( int k = j+1 ; k < (int) convPoints.size(); k++ ){
            long long dx = convPoints[j].first-convPoints[k].first;
            long long dy = convPoints[j].second-convPoints[k].second;
            maxDist = max(maxDist,dx*dx+dy*dy);
         }
      }
   }

   printf("%.10f\n",2.0+sqrt((double)maxDist));
   return 0;
}
0