結果

問題 No.2806 Cornflake Man
コンテスト
ユーザー LyricalMaestro
提出日時 2026-07-14 02:05:14
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 136 ms / 2,000 ms
+ 89µs
コード長 763 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 229 ms
コンパイル使用メモリ 96,616 KB
実行使用メモリ 152,576 KB
最終ジャッジ日時 2026-07-14 02:05:50
合計ジャッジ時間 3,881 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/2806

MOD = 998244353      


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()
    a_map = {}
    for i in range(N):
        a_map[A[i]] = i

    used = [False] * N
    used[0] = True
    answer = []
    for i in range(N):
        if used[i]:
            continue
        
        x = A[i]
        answer.append(A[i])
        while x <= M:
            if x in a_map:
                index = a_map[x]
                used[index] = True
            else:
                print(-1)
                return
            x += A[i]
    print(len(answer))
    print(" ".join(map(str, answer)))


        




        

        

        







if __name__ == "__main__":
    main()
0