結果

問題 No.202 1円玉投げ
ユーザー bal4ubal4u
提出日時 2019-06-28 21:24:24
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 1,516 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 32,380 KB
実行使用メモリ 17,512 KB
最終ジャッジ日時 2023-08-24 00:01:55
合計ジャッジ時間 2,749 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
15,488 KB
testcase_01 AC 41 ms
17,512 KB
testcase_02 AC 6 ms
7,088 KB
testcase_03 AC 6 ms
7,008 KB
testcase_04 AC 6 ms
7,012 KB
testcase_05 AC 6 ms
13,768 KB
testcase_06 AC 31 ms
16,744 KB
testcase_07 AC 34 ms
17,188 KB
testcase_08 AC 34 ms
17,260 KB
testcase_09 AC 20 ms
15,648 KB
testcase_10 AC 10 ms
14,412 KB
testcase_11 AC 16 ms
15,232 KB
testcase_12 AC 18 ms
15,280 KB
testcase_13 AC 10 ms
14,580 KB
testcase_14 AC 6 ms
13,864 KB
testcase_15 AC 20 ms
15,528 KB
testcase_16 AC 24 ms
11,080 KB
testcase_17 AC 22 ms
17,404 KB
testcase_18 AC 21 ms
17,324 KB
testcase_19 AC 19 ms
15,424 KB
testcase_20 AC 27 ms
16,500 KB
testcase_21 AC 18 ms
15,444 KB
testcase_22 AC 5 ms
7,036 KB
testcase_23 AC 5 ms
7,100 KB
testcase_24 AC 6 ms
7,028 KB
testcase_25 AC 6 ms
7,116 KB
testcase_26 AC 4 ms
13,468 KB
testcase_27 AC 4 ms
13,508 KB
testcase_28 AC 5 ms
7,008 KB
testcase_29 AC 6 ms
7,216 KB
testcase_30 AC 5 ms
13,400 KB
testcase_31 AC 4 ms
7,748 KB
testcase_32 AC 5 ms
13,388 KB
testcase_33 AC 6 ms
7,148 KB
testcase_34 AC 5 ms
7,052 KB
testcase_35 AC 22 ms
17,484 KB
testcase_36 AC 25 ms
13,524 KB
testcase_37 AC 38 ms
17,492 KB
testcase_38 AC 22 ms
17,452 KB
testcase_39 AC 5 ms
7,132 KB
testcase_40 AC 5 ms
7,072 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;
}


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