結果
| 問題 |
No.1946 ロッカーの問題
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:12:12 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,105 bytes |
| コンパイル時間 | 241 ms |
| コンパイル使用メモリ | 81,692 KB |
| 実行使用メモリ | 147,848 KB |
| 最終ジャッジ日時 | 2025-04-16 00:13:35 |
| 合計ジャッジ時間 | 2,423 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 14 |
ソースコード
import sys
def main():
input = sys.stdin.read().split()
ptr = 0
N = int(input[ptr])
ptr += 1
M = int(input[ptr])
ptr += 1
A = list(map(int, input[ptr:ptr+M])) if M > 0 else []
a_set = set(A)
# Calculate the number of divisors for each locker
d = [0] * (N + 1)
for i in range(1, N + 1):
for j in range(i, N + 1, i):
d[j] += 1
# Determine the target parity for each locker
c = [0] * (N + 1)
for j in range(1, N + 1):
if j in a_set:
c[j] = (d[j] - 1) % 2
else:
c[j] = d[j] % 2
sum_ = [0] * (N + 2) # sum[j] is the sum of x_i for i < j and i divides j (mod 2)
x = [0] * (N + 1)
for j in range(1, N + 1):
current_sum = sum_[j]
x_j = (c[j] - current_sum) % 2
x[j] = x_j
# Update sum for all multiples of j
k = 2 * j
while k <= N:
sum_[k] ^= x_j # XOR is equivalent to addition modulo 2
k += j
total = sum(x[1:N+1])
print(total)
if __name__ == '__main__':
main()
lam6er