結果

問題 No.94 圏外です。(EASY)
ユーザー 0w10w1
提出日時 2016-12-05 12:10:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 2,116 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 178,136 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 15:02:07
合計ジャッジ時間 2,685 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< string > vs;
typedef vector< double > vd;
typedef vector< vd > vvd;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N;
vi X, Y;

void init(){
  cin >> N;
  X = Y = vi( N );
  for( int i = 0; i < N; ++i )
    cin >> X[ i ] >> Y[ i ];
}

struct dsu{
  vi fa;
  dsu( int sz ){
    fa = vi( sz );
    for( int i = 0; i < sz; ++i )
      fa[ i ] = i;
  }
  int find( int x ){
    return fa[ x ] == x ? x : fa[ x ] = find( fa[ x ] );
  }
  int merge( int a, int b ){
    int x = find( a );
    int y = find( b );
    if( x == y )
      return 0;
    fa[ x ] = y;
    return 1;
  }
};

map< int, vi > group;

int eu_dis2( int a, int b, int x, int y ){
  int dx = a - x;
  int dy = b - y;
  return dx * dx + dy * dy;
}

double eu_dis( int a, int b, int x, int y ){
  double dx = a - x;
  double dy = b - y;
  return sqrt( dx * dx + dy * dy ); 
}

void preprocess(){
  dsu *uf = new dsu( N );
  for( int i = 0; i < N; ++i )
    for( int j = i + 1; j < N; ++j )
      if( eu_dis2( X[ i ], Y[ i ], X[ j ], Y[ j ] ) <= 100 )
        uf->merge( i, j );
  for( int i = 0; i < N; ++i )
    group[ uf->find( i ) ].emplace_back( i );
}

void solve(){
  double ans = N == 0 ? 1.0 : 2.0;
  for( auto it = group.begin(); it != group.end(); ++it ){
    for( int i = 0; i < it->second.size(); ++i )
      for( int j = i + 1; j < it->second.size(); ++j )
        upmax( ans, 2.0 + eu_dis( X[ ( it->second )[ i ] ], Y[ ( it->second )[ i ] ], X[ ( it->second )[ j ] ], Y[ ( it->second )[ j ] ] ) );
  }
  cout << fixed << setprecision( 8 ) << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0