結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー | matsu7874 |
提出日時 | 2015-12-14 13:57:00 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,366 bytes |
コンパイル時間 | 236 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-09-15 12:32:02 |
合計ジャッジ時間 | 8,609 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,752 KB |
testcase_01 | AC | 30 ms
10,880 KB |
testcase_02 | AC | 30 ms
10,752 KB |
testcase_03 | AC | 31 ms
10,880 KB |
testcase_04 | AC | 29 ms
10,880 KB |
testcase_05 | AC | 30 ms
10,752 KB |
testcase_06 | AC | 30 ms
10,752 KB |
testcase_07 | AC | 30 ms
10,752 KB |
testcase_08 | AC | 31 ms
10,752 KB |
testcase_09 | WA | - |
testcase_10 | AC | 30 ms
10,880 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 30 ms
10,880 KB |
testcase_14 | WA | - |
testcase_15 | AC | 358 ms
10,752 KB |
testcase_16 | AC | 152 ms
10,752 KB |
testcase_17 | AC | 31 ms
10,752 KB |
testcase_18 | WA | - |
testcase_19 | AC | 241 ms
10,752 KB |
testcase_20 | AC | 346 ms
10,880 KB |
testcase_21 | AC | 231 ms
10,752 KB |
testcase_22 | AC | 81 ms
10,752 KB |
testcase_23 | AC | 305 ms
10,880 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 354 ms
10,752 KB |
testcase_30 | AC | 37 ms
10,880 KB |
testcase_31 | WA | - |
testcase_32 | AC | 195 ms
10,880 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
ソースコード
def gcd(a, b): # 最大公約数 while b > 0: a, b = b, a % b return a def is_reachable(p, q, x, y): if p == 0: if q == 0: return x == 0 and y == 0 else: return x % q == 0 and y % q == 0 if q % 2 == 0: if p % 2 == 0: gap = 2 * p return (x % gap == 0 and y % gap == 0) or ((x + p) % gap == 0 and (y + p) % gap == 0) elif q%p == 0: return x % p == 0 and y % p == 0 else: return True else: if p%2 == 0: return True elif q%p == 0: gap = 2 * p return (x % gap == 0 and y % gap == 0) or ((x + p) % gap == 0 and (y + p) % gap == 0) else: return x % p == 0 and y % p == 0 gap = gcd(p, q) if p % 2 == q % 2: if gap == 1: return x % 2 == 0 and y % 2 == 0 elif gap == p: gap = 2 * p return (x % gap == 0 and y % gap == 0) or ((x + p) % gap == 0 and (y + p) % gap == 0) else: return (x % p == 0 and (y + gap) % p == 0) or ((x + gap) % p == 0 and y % p == 0) else: if gap == 1: return True elif gap == p: return x % p == 0 and y % p == 0 else: return (x % p == 0 and (y + gap) % p == 0) or ((x + gap) % p == 0 and y % p == 0) P, Q = map(int, input().split()) if P > Q: P, Q = Q, P # size = 100 # inf = 1000 # town = [[inf for j in range(size)] for i in range(size)] # town[0][0] = 0 # for i in range(50): # for j in range(size): # for k in range(size): # for dy, dx in ((P, Q), (P, -Q), (-P, Q), (-P, -Q), (Q, P), (Q, -P), (-Q, P), (-Q, -P)): # if town[j][k] < inf and 0 <= j + dy < size and 0 <= k + dx < size: # town[j + dy][k + # dx] = min(town[j + dy][k + dx], town[j][k] + 1) N = int(input()) cnt = 0 for i in range(N): x, y = map(int, input().split()) if is_reachable(P, Q, x, y): cnt += 1 # if town[y][x] == inf: # print(x, y, 'is NOT good child') # elif town[y][x] < inf: # print(x, y, 'is good child') print(cnt) # # for i in range(min(30, size)): # for j in range(min(30, size)): # print((' ' + str(town[i][j]))[-2:], end=' ') # print()