結果

問題 No.94 圏外です。(EASY)
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-12-20 10:02:48
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,089 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 35,164 KB
最終ジャッジ日時 2024-04-27 02:05:55
合計ジャッジ時間 584 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:71:38: error: ‘sqrt’ was not declared in this scope; did you mean ‘sqr’?
   71 |                 ans = std::max( ans, sqrt(sqr(X[j]-X[i])+sqr(Y[j]-Y[i])) );
      |                                      ^~~~
      |                                      sqr
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 #

#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