結果
| 問題 |
No.2806 Cornflake Man
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-05 11:40:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 216 ms / 2,000 ms |
| コード長 | 727 bytes |
| コンパイル時間 | 2,256 ms |
| コンパイル使用メモリ | 205,316 KB |
| 最終ジャッジ日時 | 2025-02-22 02:13:29 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
assert(2 <= n && n <= 200000);
assert(1 <= m && m <= 1000000000);
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
assert(0 <= a[i] && a[i] <= m);
}
assert(a[0] == 0);
sort(a.begin(), a.end());
map<int, int> m2;
for(int i = 0; i < n; i++){
m2[a[i]] = i;
}
vector<int> seen(n);
seen[0] = 1;
vector<int> ans;
for(int i = 0; i < n; i++){
if(seen[i]) continue;
ans.push_back(a[i]);
int x = 2*a[i];
for(int j = x; j <= m; j += a[i]){
if(!m2.count(j)){
cout << -1 << '\n';
return 0;
}
seen[m2[j]] = 1;
}
}
cout << (int)ans.size() << '\n';
for(auto x:ans) cout << x << " ";
cout << '\n';
}