結果

問題 No.202 1円玉投げ
ユーザー bal4ubal4u
提出日時 2019-06-28 21:24:24
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 1,516 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 17,436 KB
最終ジャッジ日時 2024-12-22 11:41:38
合計ジャッジ時間 2,406 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: note: 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;
}


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