結果

問題 No.2806 Cornflake Man
ユーザー umimel
提出日時 2024-07-12 21:58:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 3,869 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 187,376 KB
実行使用メモリ 14,488 KB
最終ジャッジ日時 2024-07-17 20:26:41
合計ジャッジ時間 4,193 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;
template<typename T>
struct edge{
int from;
int to;
T cost;
int id;
edge(){}
edge(int to, T cost=1) : from(-1), to(to), cost(cost){}
edge(int to, T cost, int id) : from(-1), to(to), cost(cost), id(id){}
edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id){}
void reverse(){swap(from, to);}
};
template<typename T>
struct edges : std::vector<edge<T>>{
void sort(){
std::sort(
(*this).begin(),
(*this).end(),
[](const edge<T>& a, const edge<T>& b){
return a.cost < b.cost;
}
);
}
};
template<typename T>
struct graph : std::vector<edges<T>>{
int n = 0;
int m = 0;
edges<T> es;
bool directed;
graph(int n, bool directed) : n(n), directed(directed){
(*this).resize(n);
}
void add_edge(int from, int to, T cost=1){
if(directed){
es.push_back(edge<T>(from, to, cost, m));
(*this)[from].push_back(edge<T>(from, to, cost, m++));
}else{
if(from > to) swap(from, to);
es.push_back(edge<T>(from, to, cost, m));
(*this)[from].push_back(edge<T>(from, to, cost, m));
(*this)[to].push_back(edge<T>(to, from, cost, m++));
}
}
};
template<typename T>
struct redge{
int from, to;
T cap, cost;
int rev;
redge(int to, T cap, T cost=(T)(1)) : from(-1), to(to), cap(cap), cost(cost){}
redge(int to, T cap, T cost, int rev) : from(-1), to(to), cap(cap), cost(cost), rev(rev){}
};
template<typename T> using Edges = vector<edge<T>>;
template<typename T> using weighted_graph = vector<Edges<T>>;
template<typename T> using tree = vector<Edges<T>>;
using unweighted_graph = vector<vector<int>>;
template<typename T> using residual_graph = vector<vector<redge<T>>>;
vector<long long> dijkstra(weighted_graph<long long> G, int src){
int n = (int)G.size();
vector<long long> dist(n, LINF);
dist[src] = 0;
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> PQ;
PQ.push({0, src});
while(!PQ.empty()){
int v = PQ.top().second;
long long tmp = PQ.top().first;
PQ.pop();
if(dist[v] < tmp) continue;
for(edge<long long> e : G[v]){
if(dist[v]+e.cost < dist[e.to]){
dist[e.to] = dist[v]+e.cost;
PQ.push({dist[e.to], e.to});
}
}
}
return dist;
}
void solve(){
int n, m; cin >> n >> m;
vector<int> a(n);
for(int i=0; i<n; i++) cin >> a[i];
sort(all(a));
map<int, bool> mp;
for(int i=1; i<n; i++) mp[a[i]] = false;
vector<int> ans;
for(int i=1; i<n; i++) if(!mp[a[i]]){
if(m/a[i]>n){
cout << -1 << '\n';
return;
}
for(int y=a[i]; y<=m; y+=a[i]){
if(mp.find(y) != mp.end()){
mp[y] = true;
}else{
cout << -1 << '\n';
return;
}
}
ans.pb(a[i]);
}
cout << (int)ans.size() << '\n';
for(int v : ans) cout << v << ' ';
cout << '\n';
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int T=1;
//cin >> T;
while(T--) solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0