結果

問題 No.2806 Cornflake Man
コンテスト
ユーザー tobbie
提出日時 2024-08-01 21:09:58
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 933 ms / 2,000 ms
コード長 713 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,551 ms
コンパイル使用メモリ 191,180 KB
実行使用メモリ 70,732 KB
最終ジャッジ日時 2026-04-13 17:55:43
合計ジャッジ時間 8,204 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

#define rep(i, n) for (int i = 0; i < (int)n; i++)

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  rep(i, n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  vector<int> b;
  bool ans = true;
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    int key = it->first;
    if (key == 0)
      continue;
    if (mp[key] == 1) {
      b.push_back(key);
      for (int i = 1; i * key <= m; i++) {
	if (mp[i * key] == 0)
	  ans = false;
	else
	  mp[i * key]++;
      }
    }
  }
  if (ans) {
    cout << (int)b.size() << endl;
    for (int i : b)
      cout << i << " ";
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
0