結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー ckawatak
提出日時 2019-04-09 23:51:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 855 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 82,280 KB
実行使用メモリ 118,992 KB
最終ジャッジ日時 2024-07-05 17:09:55
合計ジャッジ時間 5,697 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 TLE * 1
other WA * 1 -- * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

from queue import Queue

P,Q = list(map(int, input().split(' ')))
N = int(input())

children = {}
for i in range(N):
    x,y = list(map(int, input().split(' ')))
    if x not in children:
        children[x] = [y]
    else:
        children[x].append(y)

dx = [P, Q, -P, -Q,  P,  Q, -P, -Q]
dy = [Q, P, -Q, -P, -Q, -P,  Q,  P]

history = {}
count = 0
que = Queue()
que.put((0,0))
while not que.empty():
    if count == N:
        break
    x,y = que.get()
    for i in range(len(dx)):
        nx = x + dx[i]
        ny = y + dy[i]
        if nx not in history or ny not in history[nx]:
            if nx in children and ny in children[nx]:
                count = count + 1
            que.put((nx,ny))
            if nx not in history:
                history[nx] = [ny]
            else:
                history[nx].append(ny)

print(count)            
0