結果
問題 | No.2806 Cornflake Man |
ユーザー |
![]() |
提出日時 | 2024-07-12 22:59:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,165 ms / 2,000 ms |
コード長 | 859 bytes |
コンパイル時間 | 1,836 ms |
コンパイル使用メモリ | 180,084 KB |
実行使用メモリ | 72,224 KB |
最終ジャッジ日時 | 2024-07-17 20:27:47 |
合計ジャッジ時間 | 6,688 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); set<int> s; vector<int> ans; bool isok = true; for (int i = 0; i < n; i++) { if (a[i] == 0) continue; if (s.count(a[i])) continue; if (m / a[i] > n) { isok = false; break; } ans.push_back(a[i]); for (int j = 1; (ll)j * a[i] <= m; j++) { s.insert(j * a[i]); } } set<int> sa; for (int i = 0; i < n; i++) { sa.insert(a[i]); } for (auto v : s) { if (!sa.count(v)) { isok = false; break; } } if (isok) { int sz = ans.size(); cout << sz << endl; for (int i = 0; i < sz; i++) { cout << ans[i]; if (i == sz - 1) cout << endl; else cout << " "; } } else { cout << -1 << endl; } return 0; }