結果

問題 No.2806 Cornflake Man
ユーザー Today03Today03
提出日時 2024-07-12 22:03:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 212,796 KB
実行使用メモリ 32,896 KB
最終ジャッジ日時 2024-07-17 20:26:59
合計ジャッジ時間 5,006 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
9,216 KB
testcase_01 AC 192 ms
19,456 KB
testcase_02 AC 16 ms
5,376 KB
testcase_03 AC 197 ms
20,352 KB
testcase_04 AC 15 ms
5,376 KB
testcase_05 AC 36 ms
7,112 KB
testcase_06 AC 38 ms
6,784 KB
testcase_07 AC 249 ms
22,784 KB
testcase_08 AC 36 ms
6,656 KB
testcase_09 AC 115 ms
13,696 KB
testcase_10 AC 65 ms
10,112 KB
testcase_11 AC 9 ms
5,376 KB
testcase_12 AC 81 ms
11,392 KB
testcase_13 AC 174 ms
19,840 KB
testcase_14 AC 32 ms
7,020 KB
testcase_15 AC 330 ms
32,896 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 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;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    if (N > M + 1) {
        cout << -1 << endl;
        return 0;
    } else if (N == M + 1) {
        cout << 1 << endl
             << 1 << endl;
        return 0;
    }

    sort(A.begin(), A.end());
    set<ll> ext(A.begin(), A.end());
    set<ll> ans, seen;

    for (int i = 1; i < N; i++) {
        if (M / A[i] + 1 > N) {
            cout << -1 << endl;
            return 0;
        }
        if (!seen.count(A[i])) {
            ans.insert(A[i]);
            for (ll x = A[i]; x <= M; x += A[i]) {
                if (!ext.count(x)) {
                    cout << -1 << endl;
                    return 0;
                }
                seen.insert(x);
            }
        }
    }

    cout << ans.size() << endl;
    for (int x : ans) {
        cout << x << ' ';
    }
    cout << endl;
}
0