結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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++) printf("%d ", id[i]); printf("\n");
		
	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