結果
問題 |
No.1946 ロッカーの問題
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:57:39 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,047 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 149,120 KB |
最終ジャッジ日時 | 2025-06-12 13:58:15 |
合計ジャッジ時間 | 13,563 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 14 |
ソースコード
import sys import math def is_square(n): root = math.isqrt(n) return root * root == n def main(): input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 M = int(input[idx]) idx += 1 A = list(map(int, input[idx:idx+M])) if M > 0 else [] A_set = set(A) # Precompute c_k for all k c = [0] * (N + 1) for k in range(1, N + 1): if k in A_set: c_k = 0 if is_square(k) else 1 else: c_k = 1 if is_square(k) else 0 c[k] = c_k x = [0] * (N + 1) for k in range(1, N + 1): sum_d = 0 # Collect all divisors d < k of k sqrt_k = math.isqrt(k) for d in range(1, sqrt_k + 1): if k % d == 0: if d < k: sum_d += x[d] other = k // d if other != d and other < k: sum_d += x[other] sum_d %= 2 x[k] = (c[k] - sum_d) % 2 print(sum(x[1:N+1])) if __name__ == '__main__': main()