結果

問題 No.202 1円玉投げ
ユーザー rpy3cpp
提出日時 2015-05-03 23:52:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,204 ms / 5,000 ms
コード長 1,027 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 48,560 KB
最終ジャッジ日時 2024-12-22 06:34:58
合計ジャッジ時間 16,963 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import collections

def read_data():
    N = int(input())
    lines = sys.stdin.readlines()
    XY = []
    for xy in lines:
        x, y = map(int, xy.split())
        XY.append((x, y))
    return N, XY

def solve(N, XY, r = 10, size = 50):
    cells = collections.defaultdict(list)
    count = 0
    threshold = 4 * r * r
    for x, y in XY:
        if not overlap(x, y, cells, size, threshold):
            count += 1
            register_cell(x, y, cells, size)
    return count

def overlap(x, y, cells, size, threshold):
    xc = x // size
    yc = y // size
    for xr in [xc-1, xc, xc+1]:
        for yr in [yc-1, yc, yc+1]:
            if (xr, yr) in cells:
                for xx, yy in cells[xr, yr]:
                    if (x - xx) ** 2 + (y - yy) ** 2 < threshold:
                        return True
    return False

def register_cell(x, y, cells, size):
    xc = x // size
    yc = y // size
    cells[xc, yc].append((x, y))

if __name__ == "__main__":
    N, XY = read_data()
    print(solve(N, XY))
0