結果

問題 No.168 ものさし
ユーザー 0w10w1
提出日時 2016-12-05 13:59:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 2,071 bytes
コンパイル時間 1,993 ms
コンパイル使用メモリ 182,064 KB
実行使用メモリ 12,176 KB
最終ジャッジ日時 2023-08-25 21:04:21
合計ジャッジ時間 3,339 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
5,156 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 14 ms
5,104 KB
testcase_12 AC 45 ms
11,968 KB
testcase_13 AC 64 ms
12,104 KB
testcase_14 AC 63 ms
11,976 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 60 ms
11,868 KB
testcase_20 AC 63 ms
12,176 KB
testcase_21 AC 63 ms
11,812 KB
testcase_22 AC 63 ms
11,644 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 ];
}

vector< tuple< ll, int, int > > edge;

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

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 x, int y ){
    int a = find( x );
    int b = find( y );
    if( a == b )
      return 0;
    fa[ b ] = a;
    return 1;
  }
};

void preprocess(){
  for( int i = 0; i < N; ++i )
    for( int j = i + 1; j < N; ++j ){
      ll dis2 = eu_dis2( X[ i ], Y[ i ], X[ j ], Y[ j ] );
      edge.emplace_back( dis2, i, j );
    }
  sort( edge.begin(), edge.end() );
  dsu *uf = new dsu( N );
  for( int i = 0; i < edge.size(); ++i ){
    ll d; int x, y; tie( d, x, y ) = edge[ i ];
    uf->merge( x, y );
    if( uf->find( 0 ) == uf->find( N - 1 ) ){
      ll ans = -1;
      for( ll lb = 10, ub = ( ll ) 4e9; lb <= ub; ){
        ll mid = ( lb + ub ) / 2;
        if( mid * mid >= d )
          ans = mid, ub = mid - 1;
        else
          lb = mid + 1;
      }
      if( ans % 10 > 0 )
        ans = ans / 10 * 10 + 10;
      cout << ans << endl;
      exit( 0 );
    }
  }
}

void solve(){
  
}

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