結果

問題 No.2806 Cornflake Man
ユーザー 沙耶花沙耶花
提出日時 2024-07-12 21:23:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 3,860 ms
コンパイル使用メモリ 269,556 KB
実行使用メモリ 22,272 KB
最終ジャッジ日時 2024-07-17 20:25:33
合計ジャッジ時間 6,216 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
13,824 KB
testcase_01 AC 156 ms
18,560 KB
testcase_02 AC 21 ms
6,944 KB
testcase_03 AC 171 ms
19,200 KB
testcase_04 AC 18 ms
6,940 KB
testcase_05 AC 30 ms
7,040 KB
testcase_06 AC 50 ms
9,600 KB
testcase_07 AC 218 ms
21,504 KB
testcase_08 AC 45 ms
9,216 KB
testcase_09 AC 94 ms
13,056 KB
testcase_10 AC 46 ms
8,576 KB
testcase_11 AC 7 ms
6,940 KB
testcase_12 AC 61 ms
9,856 KB
testcase_13 AC 131 ms
16,428 KB
testcase_14 AC 24 ms
6,940 KB
testcase_15 AC 168 ms
22,272 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int main(){

	int N,M;
	cin>>N>>M;
	set<long long> S;
	
	rep(i,N){
		int t;
		cin>>t;
		S.insert(t);
	}
	auto T = S;
	vector<long long> ans;
	while(S.size()>0){
		auto it = S.begin();
		long long v = *it;
		S.erase(it);
		if(v==0)continue;
		ans.push_back(v);
		for(long long j=v*2;j<=M;j+=v){
			if(!T.count(j)){
				cout<<-1<<endl;
				return 0;
			}
			S.erase(j);
		}
	}
	cout<<ans.size()<<endl;
	rep(i,ans.size()){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
	return 0;
}
0