結果

問題 No.2806 Cornflake Man
ユーザー zeta7532zeta7532
提出日時 2024-07-09 21:20:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 1,556 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 222,652 KB
実行使用メモリ 28,392 KB
最終ジャッジ日時 2024-07-17 20:25:21
合計ジャッジ時間 4,381 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
6,816 KB
testcase_01 AC 133 ms
12,032 KB
testcase_02 AC 13 ms
6,944 KB
testcase_03 AC 141 ms
12,416 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 26 ms
6,944 KB
testcase_06 AC 30 ms
6,940 KB
testcase_07 AC 175 ms
13,824 KB
testcase_08 AC 27 ms
6,940 KB
testcase_09 AC 81 ms
8,832 KB
testcase_10 AC 56 ms
8,540 KB
testcase_11 AC 8 ms
6,940 KB
testcase_12 AC 70 ms
9,280 KB
testcase_13 AC 156 ms
15,796 KB
testcase_14 AC 27 ms
6,940 KB
testcase_15 AC 249 ms
28,392 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)

int main() {
    ll N,M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(all(A));
    vector<ll> B;
    set<pair<ll,ll>> now;
    rep(i,N){
        if(A[i]==0) continue;
        bool ok=true;
        if(i>1){
            auto it=*now.begin();
            if(it.fi<A[i]){
                cout << -1 << endl;
                return 0;
            }
            if(it.fi==A[i]) ok=false;
        }
        if(ok){
            B.push_back(A[i]);
            now.insert({A[i]*2,A[i]});
        }
        while(1){
            auto now_it=*now.begin();
            if(now_it.fi==A[i]){
                now.erase(now_it);
                now.insert({now_it.fi+now_it.se,now_it.se});
            }else{
                break;
            }
        }
    }
    set<ll> s;
    rep(i,N) s.insert(A[i]); 
    bool ans=true;
    rep(i,B.size()){
        for(ll j=0;j<=M;j+=B[i]){
            if(s.find(j)==s.end()) ans=false;
            if(!ans) break;
        }
        if(!ans) break;
    }
    if(ans){
        cout << B.size() << endl;
        rep(i,B.size()){
            cout << B[i] << " ";
        }
        cout << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}
0