結果

問題 No.2806 Cornflake Man
ユーザー tobbietobbie
提出日時 2024-08-01 21:09:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,174 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 178,984 KB
実行使用メモリ 70,716 KB
最終ジャッジ日時 2024-08-01 21:10:10
合計ジャッジ時間 9,797 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,174 ms
66,944 KB
testcase_01 AC 152 ms
11,008 KB
testcase_02 AC 225 ms
24,960 KB
testcase_03 AC 173 ms
11,264 KB
testcase_04 AC 178 ms
16,256 KB
testcase_05 AC 31 ms
6,944 KB
testcase_06 AC 898 ms
70,716 KB
testcase_07 AC 211 ms
12,672 KB
testcase_08 AC 521 ms
39,552 KB
testcase_09 AC 92 ms
8,320 KB
testcase_10 AC 50 ms
6,940 KB
testcase_11 AC 7 ms
6,940 KB
testcase_12 AC 62 ms
6,940 KB
testcase_13 AC 136 ms
9,856 KB
testcase_14 AC 25 ms
6,940 KB
testcase_15 AC 221 ms
13,804 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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