結果
| 問題 |
No.2806 Cornflake Man
|
| コンテスト | |
| ユーザー |
YuuuT
|
| 提出日時 | 2024-07-12 22:09:11 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,508 bytes |
| コンパイル時間 | 1,341 ms |
| コンパイル使用メモリ | 126,448 KB |
| 実行使用メモリ | 39,168 KB |
| 最終ジャッジ日時 | 2024-07-12 22:10:17 |
| 合計ジャッジ時間 | 11,226 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 11 TLE * 3 -- * 2 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;
const long long inf = 1e18;
const int mod = 998244353;
int N, M;
vector<int> A;
set<int> AS, ok, ng;
int judge(int a) {
vector<int> num;
for (int i = 2; i * i <= a; ++i) {
if (a % i != 0) continue;
if (ng.find(i) == ng.end()) num.push_back(i);
if (a / i != i && ng.find(a / i) == ng.end()) num.push_back(a / i);
}
num.push_back(a);
sort(num.begin(), num.end());
for (int j : num) {
int tmp = j;
while (tmp <= A.back()) {
if (AS.find(tmp) == AS.end()) {
ng.insert(j);
break;
}
tmp += j;
}
if (ng.find(j) != ng.end()) continue;
tmp = j;
while (tmp <= A.back()) {
ok.insert(tmp);
tmp += j;
}
return j;
}
return -1;
}
int main() {
cin >> N >> M;
A.resize(N);
for (int i = 0; i < N; ++i) cin >> A[i];
sort(A.begin(), A.end());
AS = set<int>(A.begin(), A.end());
vector<int> ans;
for (int i = 1; i < N; ++i) {
if (ok.find(A[i]) != ok.end()) continue;
int res = judge(A[i]);
if (res == -1) {
cout << -1 << endl;
return 0;
}
ans.push_back(res);
}
sort(ans.begin(), ans.end());
cout << ans.size() << endl;
for (int a : ans) cout << a << " ";
cout << endl;
return 0;
}
YuuuT