結果

問題 No.94 圏外です。(EASY)
ユーザー bal4ubal4u
提出日時 2019-07-28 05:18:38
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,617 bytes
コンパイル時間 1,876 ms
コンパイル使用メモリ 31,300 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 11:22:52
合計ジャッジ時間 1,249 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 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,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 0 ms
4,380 KB
testcase_21 AC 0 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: 備考: in expansion of macro ‘gc’
   15 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.94 圏外です。(EASY)
// 2019.7.28 bal4u

#include <stdio.h>
#include <math.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()   // 整数の入力(負数対応)
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX 1003

/* UNION-FIND library */
int id[MAX], size[MAX];
void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; }
int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; }
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q) {
    int i = root(p), j = root(q); if (i == j) return;
    if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j];
}

int N;
int x[MAX], y[MAX];
int hi[MAX], grp[MAX][MAX];
int idx[MAX], gz = 1;

int dis(int i, int j) {
	int dx = x[i]-x[j], dy = y[i]-y[j];
	return dx*dx + dy*dy;
}

int main()
{
	int i, j, k, ans;
	
	N = in(); init(N);
	if (N == 0) { puts("1.000000000000"); return 0; }
	for (i = 0; i < N; i++) x[i] = in(), y[i] = in();
	for (i = 1; i < N; i++) for (j = 0; j < i; j++) {
		if (dis(i, j) <= 100) unite(i, j);
	}
	for (i = 0; i < N; i++) {
		j = root(i);
		if (idx[j] == 0) idx[j] = gz++;
		k = idx[j];
		grp[k][hi[k]++] = i;
	}

	ans = 0;
	for (k = 1; k < gz; k++) {
		for (i = 0; i < hi[k]; i++) for (j = i+1; j < hi[k]; j++) {
			int a = dis(grp[k][i], grp[k][j]);
			if (a > ans) ans = a;
		}
	}
	printf("%.12lf\n", sqrt(ans)+2);
	return 0;
}
0