結果

問題 No.2806 Cornflake Man
ユーザー wgrape
提出日時 2024-11-11 13:35:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 160,384 KB
最終ジャッジ日時 2024-11-11 13:35:23
合計ジャッジ時間 5,430 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Aset = set(A)
if A[0] != 0:
    print(-1)
    exit(0)

checked = set()
ans = []
for i in range(1, N):
    # あるべき数を全て走査する
    if A[i] in checked: # 走査されていれば飛ばす
        continue
    ans.append(A[i])
    for j in range(A[i] * 2, M + 1, A[i]): # すべてチェックする。鳩ノ巣原理より10^9に行く前に落ちる
        if j not in Aset:
            print(-1)
            exit(0)
        checked.add(j)
    
print(len(ans))
print(*ans)
    
    

0