-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbadstory.cpp
68 lines (61 loc) · 1.4 KB
/
badstory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
void solve() {
ll n;
cin >> n;
set<ll> a;
set<ll> twice;
for (ll i = 0; i < n; i++) {
ll c;
cin >> c;
if (a.find(c) != a.end()) twice.insert(c);
a.insert(c);
}
set<ll> include;
for (ll i : a) {
for (ll j : a) {
if (i == j && twice.find(i) == twice.end()) continue;
ll x = abs(i - j);
if (a.find(x) == a.end()) {
include.insert(x);
}
}
}
while (!include.empty() && a.size() <= 300) {
while(!include.empty()) {
auto x = include.begin();
a.insert(*x);
include.erase(x);
}
for (ll i : a) {
for (ll j : a) {
if (i == j && twice.find(i) == twice.end()) continue;
ll x = abs(i - j);
if (a.find(x) == a.end()) {
include.insert(x);
}
}
}
}
if(a.size() > 300 || !include.empty()) {
cout << "NO" << endl;
return;
} else {
cout << "YES" << endl;
cout << a.size() << endl;
for (ll i : a) cout << i << " ";
cout << endl;
}
return;
}
int main() {
ll t;
cin >> t;
while (t--) {
solve();
}
return 0;
}