結果
問題 |
No.2806 Cornflake Man
|
ユーザー |
|
提出日時 | 2024-07-12 22:29:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 470 ms / 2,000 ms |
コード長 | 739 bytes |
コンパイル時間 | 2,211 ms |
コンパイル使用メモリ | 204,672 KB |
最終ジャッジ日時 | 2025-02-22 04:32:13 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main () { int N, M; cin >> N >> M; std::vector<int> A(N); set<int> st, st2; for (auto& a : A) { cin >> a; st.insert(a); st2.insert(a); } sort(A.begin(), A.end()); vector<int> ans; for (int i = 1; i < N; i ++) { int a = A[i]; if (st2.find(a) == st2.end()) continue; bool ok = true; for (int x = a; x <= M; x += a) { if (st.find(x) == st.end()) { ok = false; break; } else if (st2.find(x) != st2.end()) { st2.erase(x); } } if (!ok) { puts("-1"); return 0; } else { ans.push_back(a); } } cout << ans.size() << endl; for (int i = 0; i < ans.size(); i ++) { cout << ans[i] << (i < ans.size() - 1 ? " " : ""); } cout << endl; }