結果

問題 No.2806 Cornflake Man
ユーザー Pres1dent
提出日時 2024-07-12 22:30:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 201,980 KB
最終ジャッジ日時 2025-02-22 04:33:11
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m; cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> ans;
  set<int> st(a.begin() + 1, a.end()), played;
  for (auto e : st) {
    if (played.count(e)) continue;
    ans.push_back(e);
    for (int i = 1; e * i <= m; i++) {
      if (not st.count(e * i)) {
        cout << -1 << endl;
        return 0;
      }
      played.insert(e * i);
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << (i + 1 == ans.size() ? "\n" : " ");
  }
}
0