結果

問題 No.2806 Cornflake Man
ユーザー kusaf_kusaf_
提出日時 2024-07-12 21:34:39
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 3,333 ms
コンパイル使用メモリ 266,280 KB
実行使用メモリ 16,296 KB
最終ジャッジ日時 2024-07-17 20:26:02
合計ジャッジ時間 5,504 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, K;
  cin >> N >> K;

  vector<ll> A(N);
  set<ll> s;
  for(auto &i : A) {
    cin >> i;
    if(i) { s.insert(i); }
  }
  ranges::sort(A);

  vector<ll> ans;
  for(ll i = 0; i < N; i++) {
    if(!s.count(A[i])) { continue; }
    ans.emplace_back(A[i]);
    for(ll j = A[i] * 2; j <= K; j += A[i]) {
      if(ranges::upper_bound(A, j) == ranges::lower_bound(A, j)) {
        cout << -1 << "\n";
        return 0;
      }
      s.erase(j);
    }
  }

  cout << ans.size() << "\n";
  for(auto &i : ans) { cout << i << " "; }
}
0