結果

問題 No.2806 Cornflake Man
ユーザー keisuke6keisuke6
提出日時 2024-07-04 23:50:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 536 bytes
コンパイル時間 2,080 ms
コンパイル使用メモリ 215,792 KB
実行使用メモリ 17,364 KB
最終ジャッジ日時 2024-07-17 20:25:18
合計ジャッジ時間 3,986 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
8,936 KB
testcase_01 AC 87 ms
11,000 KB
testcase_02 AC 17 ms
5,376 KB
testcase_03 AC 85 ms
11,176 KB
testcase_04 AC 16 ms
5,376 KB
testcase_05 AC 20 ms
5,376 KB
testcase_06 AC 44 ms
6,672 KB
testcase_07 AC 102 ms
14,196 KB
testcase_08 AC 38 ms
6,252 KB
testcase_09 AC 49 ms
8,756 KB
testcase_10 AC 39 ms
6,688 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 48 ms
7,168 KB
testcase_13 AC 99 ms
11,376 KB
testcase_14 AC 20 ms
5,376 KB
testcase_15 AC 124 ms
17,364 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed 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());
	vector<bool> P(N);
	unordered_map<int,int> m;
	for(int i=0;i<N;i++) m[A[i]] = i;
	vector<int> s = {};
	for(int i=1;i<N;i++)if(!P[i]){
		P[i] = true;
		s.push_back(A[i]);
		for(int j=A[i];j<=M;j+=A[i]){
			if(!m.count(j)){
				cout<<-1<<endl;
				return 0;
			}
			P[m[j]] = true;
		}
	}
	cout<<s.size()<<endl;
	for(int x:s) cout<<x<<' ';
	cout<<endl;
}
0