結果

問題 No.2806 Cornflake Man
ユーザー reirei
提出日時 2024-07-12 21:51:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,290 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 116,768 KB
実行使用メモリ 22,144 KB
最終ジャッジ日時 2024-07-17 20:26:29
合計ジャッジ時間 3,716 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
13,696 KB
testcase_01 AC 157 ms
18,560 KB
testcase_02 AC 14 ms
6,940 KB
testcase_03 AC 160 ms
19,200 KB
testcase_04 AC 13 ms
6,944 KB
testcase_05 AC 25 ms
6,944 KB
testcase_06 AC 36 ms
9,472 KB
testcase_07 AC 229 ms
21,376 KB
testcase_08 AC 33 ms
8,960 KB
testcase_09 AC 91 ms
12,928 KB
testcase_10 AC 47 ms
8,576 KB
testcase_11 AC 6 ms
6,940 KB
testcase_12 AC 60 ms
9,856 KB
testcase_13 AC 146 ms
16,448 KB
testcase_14 AC 21 ms
6,940 KB
testcase_15 AC 218 ms
22,144 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i8 = int8_t;
using i32 = int;
using i64 = long long;
// using i128 = __int128;
using u64 = unsigned long long;
using ll = long long;

void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}

i64 pow(i64 j, i64 n) {
  i64 res = 1;
  while (n > 0) {
    if (n & 1)
      res *= j;
    j *= j;
    n >>= 1;
  }
  return res;
}

i64 n, m;
void _main() {
  cin >> n >> m;
  set<i64> a;
  bool zero = false;
  for (i64 i = 0; i < n; i++) {
    i64 b;
    cin >> b;
    if (b == 0) {
      zero = true;
      continue;
    }
    a.insert(b);
  }
  set<i64> b = a;
  if (zero) {
    b.insert(0);
  }
  vector<i64> ans;
  while (!a.empty()) {
    i64 x = *a.begin();
    ans.push_back(x);
    for (i64 i = 0; x * i <= m; i++) {
      if (!b.count(x * i)) {
        cout << "-1\n";
        return;
      }
      if (a.count(x * i)) {
        a.erase(x * i);
      }
    }
  }
  cout << ans.size() << "\n";
  for (i64 i = 0; i < ans.size(); i++) {
    cout << ans[i] << (i + 1 == ans.size() ? "\n" : " ");
  }
}
0