結果

問題 No.168 ものさし
ユーザー bal4ubal4u
提出日時 2019-07-15 19:27:19
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,685 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 31,900 KB
実行使用メモリ 9,660 KB
最終ジャッジ日時 2023-08-18 09:43:51
合計ジャッジ時間 2,339 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// yukicoder: No.168 ものさし
// 2019.7.15 bal4u

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

typedef long long ll;

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

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '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];
}

typedef struct { int i, j; ll w; } T;
T t[500005]; int sz;
int N;
int x[MAX], y[MAX];

void Qsort(T *a, int l, int r) {
	int i,j; T t; ll m;
	
	i = l, j = r, m = a[(l+r) >> 1].w;
	while (1) {
		while (a[i].w < m) i++;
		while (m < a[j].w) j--;
		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}

int main()
{
	int i, j;
	ll a, ans;

	N = in(); for (i = 0; i < N; i++) x[i] = in(), y[i] = in();
	init(N);
	for (i = 0; i < N; i++) for (j = i+1; j < N; j++) {
		ll dx = x[i] - x[j], dy = y[i] - y[j];
		t[sz].i = i, t[sz].j = j, t[sz++].w = dx*dx + dy*dy;
	}
	Qsort(t, 0, sz-1);
	ans = 0; for (i = 0; i < sz; i++) {
		if (!connected(t[i].i, t[i].j)) {
			ans = t[i].w, unite(t[i].i, t[i].j);
			if (connected(0, N-1)) break;
		}
	}
	a = sqrt((double)ans);
	if (a*a < ans) a++;
	printf("%lld\n", ((a-1)/10+1)*10);
	return 0;
}
0