結果

問題 No.1946 ロッカーの問題
ユーザー H20
提出日時 2022-04-10 18:49:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,644 ms / 3,000 ms
コード長 797 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 134,148 KB
最終ジャッジ日時 2024-12-21 10:18:52
合計ジャッジ時間 15,393 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N,M = map(int, input().split())
A = list(map(int, input().split()))
if not (1<=2*10**5 and 0<=M<=N and len(A)==M and A==sorted(A) and M == len(set(A))):
    exit()

DIV = [[]]
ALL = [0]*(N+1)
DOOR= [0]*(N+1)
for i in range(1,N+1):
    DIV.append(make_divisors(i))
    for div in DIV[i]:
        ALL[div] = (ALL[div]+1)%2
for a in A:
    DOOR[a]=1

cnt = 0
for i in reversed(range(N+1)):
    if ALL[i]!=DOOR[i]:
        cnt+=1
        for div in DIV[i]:
            DOOR[div] = (DOOR[div]+1)%2
print(cnt)
0