結果

問題 No.202 1円玉投げ
ユーザー bal4ubal4u
提出日時 2019-06-28 22:12:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 531 ms / 5,000 ms
コード長 1,689 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 30,220 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 00:02:06
合計ジャッジ時間 4,786 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
4,376 KB
testcase_01 AC 80 ms
4,380 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 4 ms
4,380 KB
testcase_06 AC 85 ms
4,376 KB
testcase_07 AC 103 ms
4,376 KB
testcase_08 AC 105 ms
4,380 KB
testcase_09 AC 43 ms
4,376 KB
testcase_10 AC 13 ms
4,376 KB
testcase_11 AC 31 ms
4,376 KB
testcase_12 AC 34 ms
4,376 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 40 ms
4,376 KB
testcase_16 AC 44 ms
4,380 KB
testcase_17 AC 363 ms
4,376 KB
testcase_18 AC 359 ms
4,376 KB
testcase_19 AC 35 ms
4,380 KB
testcase_20 AC 70 ms
4,376 KB
testcase_21 AC 36 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 0 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 526 ms
4,380 KB
testcase_36 AC 89 ms
4,376 KB
testcase_37 AC 117 ms
4,376 KB
testcase_38 AC 531 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: 備考: in expansion of macro ‘gc’
   15 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.202 1円玉投げ
// 2019.6.28 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

typedef struct { int x, y, id; } T;
T t[100005]; int N;
int id[100005];
char f[100005];

int cmp(const void *a, const void *b) {
	int t = ((T *)a)->x - ((T *)b)->x;
	if (t) return t;
	return ((T *)a)->y - ((T *)b)->y;
}

// 見つからなければ、一つ大きい要素を返す。つまり、 >= x
int low_bound(int x)
{
	int m, l = 0, r = N;

    while (l < r) {
        m = (l+r) >> 1;
        if (t[m].x < x) l = m + 1; else r = m;
    }
	return l;
}

// 見つからなければ、一つ小さい要素を返す
int upper_bound(int x)
{
	int m, l = 0, r = N;

    while (l < r) {
        m = (l+r) >> 1;
        if (t[m].x <= x) l = m + 1; else r = m;
    }
	return l-1;
}

int overlap(int x1, int x2, int y1, int y2) {
	int dx, dy;
	dx = x1 - x2;
	if (dx < 0) dx = -dx;
	if (dx >= 20) return 0;
	dy = y1 - y2;
	if (dy < 0) dy = -dy;
	if (dy >= 20) return 0;
	return (dx*dx + dy*dy) < 400;
}

int main()
{
	int i, j, x, y, r, ans;

	ans = N = in();
	for (i = 0; i < N; i++) t[i].x = in(), t[i].y = in(), t[i].id = i;
	memset(f, 1, N);
	qsort(t, N, sizeof(T), cmp);
	for (i = 0; i < N; i++) id[t[i].id] = i;
	
	for (i = 0; i < N; i++) if (f[i]) {
		x = t[id[i]].x;
		j = low_bound(x-20), r = upper_bound(x+20);
		while (j <= r) {
			y = t[j].id;
			if (f[y] && y != i) {
				if (overlap(x, t[j].x, t[id[i]].y, t[j].y)) f[y] = 0, ans--;
			}
			j++;
		}
	}
	printf("%d\n", ans);
	return 0;
}
0