結果

問題 No.202 1円玉投げ
コンテスト
ユーザー bal4u
提出日時 2019-06-28 21:24:24
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 68 ms / 5,000 ms
コード長 1,516 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 386 ms
コンパイル使用メモリ 40,648 KB
最終ジャッジ日時 2026-02-22 03:42:44
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// 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;
}


int *p[1005][1005], hi[1005][1005]; int N;
int mv[9][2] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,0},{0,1},{1,-1},{1,0},{1,1}};
int x[100005], y[100005];
char f[100005];

int overlap(int l, int r) {
	int dx, dy;
	if (r == l) return 0;
	dx = x[l] - x[r];
	if (dx < 0) dx = -dx;
	if (dx >= 20) return 0;
	dy = y[l] - y[r];
	if (dy < 0) dy = -dy;
	if (dy >= 20) return 0;
	return (dx*dx + dy*dy) < 400;
}

int main()
{
	int i, j, k, t, r, c, rr, cc, ans;

	ans = N = in();
	memset(f, 1, N);
	for (i = 0; i < N; i++) {
		x[i] = in(), y[i] = in();
		hi[y[i]/20][x[i]/20]++;
	}
	for (r = 0; r <= 1000; r++) for (c = 0; c <= 1000; c++) if (hi[r][c]) {
		p[r][c] = malloc(hi[r][c] * sizeof(int));
	}
	
	memset(hi, 0, sizeof(hi));
		
	for (i = 0; i < N; i++) {
		r = y[i]/20, c = x[i]/20;
		k = hi[r][c]++;
		p[r][c][k] = i;
	}
	
	for (i = 0; i < N; i++) if (f[i]) {
		r = y[i]/20, c = x[i]/20;
		for (j = 0; j < 9; j++) {
			rr = r + mv[j][0], cc = c + mv[j][1];
			if (rr < 0 || rr > 1000 || cc < 0 || cc > 1000) continue;
			for (k = 0; k < hi[rr][cc]; ) if (f[t = p[rr][cc][k]]) {
				if (!overlap(i, t)) k++;
				else {
					ans--, f[t] = 0, p[rr][cc][k] = p[rr][cc][--hi[rr][cc]];
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}
0