結果
| 問題 |
No.2806 Cornflake Man
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-12 23:29:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,710 bytes |
| コンパイル時間 | 1,878 ms |
| コンパイル使用メモリ | 175,004 KB |
| 実行使用メモリ | 18,104 KB |
| 最終ジャッジ日時 | 2024-07-12 23:29:34 |
| 合計ジャッジ時間 | 8,802 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "algo/debug.h"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
bool isDivisible(int x, const vector<int>& nonDiv) {
// Use binary search to check if x is divisible by any element in nonDiv
for (int elem : nonDiv) {
if (elem > x) break; // Since the array is sorted, no need to check further
if (x % elem == 0) return true;
}
return false;
}
vector<int> printNonDivisibleElements(const vector<int>& arr) {
int n = arr.size();
vector<int> nonDiv; // To store non-divisible elements
// Iterate through the sorted array
for (int i = 0; i < n; ++i) {
// Check if the current element is divisible by any in nonDiv
if (!isDivisible(arr[i], nonDiv)) {
nonDiv.push_back(arr[i]); // Add to non-divisible list
}
}
// Print the result
return nonDiv;
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (auto &x : a) {
cin >> x;
}
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
a.pop_back();
reverse(a.begin(), a.end());
auto p = printNonDivisibleElements(a);
for (auto &x : p) {
int c = 0;
for (int j = 0; j < a.size(); j++) {
c += (a[j] % x == 0);
}
if (c != (m / x)) {
cout << -1 << '\n'; return;
}
}
cout << p.size() << "\n";
for (auto &x : p) {
cout << x << " ";
}
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
#endif
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
// cerr << "Time elapsed: " << ((long double)clock() / CLOCKS_PER_SEC) << " s.\n";
}