結果

問題 No.94 圏外です。(EASY)
コンテスト
ユーザー Ysmr_Ry
提出日時 2014-12-20 10:02:48
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,089 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 971 ms
コンパイル使用メモリ 171,484 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 16:00:50
合計ジャッジ時間 1,873 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:52:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   52 |         scanf( "%d", &N );
      |         ~~~~~^~~~~~~~~~~~
main.cpp:54:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |                 scanf( "%d%d", X+i, Y+i );
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include<cstdio>
#include<algorithm>
#include<numeric>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)
#define all(a) (a).begin(), (a).end()

struct UnionFind
{
	std::vector<int> par, rank;

	UnionFind( std::size_t sz )
	:	par(sz), rank(sz)
	{ std::iota( all(par), 0 ); }

	int find( int x )
	{ return x==par[x]?x:par[x]=find(par[x]); }

	void unite( int x, int y )
	{
		x = find(x);
		y = find(y);
		
		if( x == y )
			return;

		if( rank[x] < rank[y] )
			par[x] = y;
		else
		{
			par[y] = x;

			if( rank[x] == rank[y] )
				++rank[x];
		}

		return;
	}

	bool same( int x, int y )
	{ return find(x) == find(y); }
};

int N;
int X[1000], Y[1000];

int sqr( int x )
{ return x*x; }

int main()
{
	scanf( "%d", &N );
	rep( i, N )
		scanf( "%d%d", X+i, Y+i );

	UnionFind uf( N );

	rep( i, N )
	{
		rep( j, i )
		{
			int d = sqr(X[j]-X[i])+sqr(Y[j]-Y[i]);

			if( d <= 100 )
				uf.unite( i, j );
		}
	}

	double ans = 0;
	rep( i, N ) rep( j, i ) if( uf.same( i, j ) )
		ans = std::max( ans, sqrt(sqr(X[j]-X[i])+sqr(Y[j]-Y[i])) );

	printf( "%.9f\n", N?ans+2:1 );

	return 0;
}
0