結果

問題 No.2806 Cornflake Man
ユーザー shobonvipshobonvip
提出日時 2024-07-12 21:24:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,772 bytes
コンパイル時間 4,529 ms
コンパイル使用メモリ 269,024 KB
実行使用メモリ 11,624 KB
最終ジャッジ日時 2024-07-17 20:25:36
合計ジャッジ時間 5,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
5,248 KB
testcase_01 AC 63 ms
5,376 KB
testcase_02 AC 12 ms
5,376 KB
testcase_03 AC 68 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 14 ms
5,376 KB
testcase_06 AC 29 ms
5,376 KB
testcase_07 AC 76 ms
5,376 KB
testcase_08 AC 27 ms
5,376 KB
testcase_09 AC 40 ms
5,376 KB
testcase_10 AC 34 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 42 ms
5,376 KB
testcase_13 AC 84 ms
7,216 KB
testcase_14 AC 18 ms
5,376 KB
testcase_15 AC 116 ms
11,624 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 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	rep(i,0,n){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	priority_queue<pair<ll,ll>> pq;
	rep(i,1,n){
		if (pq.empty()){
			pq.push(pair(- a[i] * 2, a[i]));
			continue;
		}
		if (- pq.top().first < a[i]){
			cout << -1 << '\n';
			return 0;
		}
		if (!(- pq.top().first == a[i])){
			pq.push(pair(-a[i] * 2, a[i]));
		}else{
			while(- pq.top().first == a[i]){
				auto [x, y] = pq.top();
				pq.pop();
				pq.push(pair(x-y, y));
			}
		}
	}

	vector<ll> ans;
	while(!pq.empty()){
		auto [x, y] = pq.top();
		pq.pop();
		ans.push_back(y);
	}
	sort(ans.begin(), ans.end());
	
	int k = ans.size();
	cout << k << endl;
	rep(i,0,k){
		cout << ans[i] << ' ';
	}
	cout << '\n';
}

0