結果

問題 No.2806 Cornflake Man
ユーザー silv723silv723
提出日時 2024-07-05 11:40:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 2,231 ms
コンパイル使用メモリ 213,576 KB
実行使用メモリ 15,496 KB
最終ジャッジ日時 2024-07-17 20:25:16
合計ジャッジ時間 4,615 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
9,216 KB
testcase_01 AC 154 ms
12,032 KB
testcase_02 AC 19 ms
6,940 KB
testcase_03 AC 168 ms
12,416 KB
testcase_04 AC 17 ms
6,940 KB
testcase_05 AC 30 ms
6,940 KB
testcase_06 AC 47 ms
6,944 KB
testcase_07 AC 206 ms
13,696 KB
testcase_08 AC 43 ms
6,944 KB
testcase_09 AC 97 ms
8,832 KB
testcase_10 AC 46 ms
6,944 KB
testcase_11 AC 6 ms
6,940 KB
testcase_12 AC 58 ms
7,040 KB
testcase_13 AC 122 ms
10,880 KB
testcase_14 AC 23 ms
6,940 KB
testcase_15 AC 162 ms
15,496 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0