0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:11:58 +00:00

C - 3SUM Closure

https://codeforces.com/contest/1698/submission/162104497
This commit is contained in:
Baoshuo Ren 2022-06-28 23:25:20 +08:00
parent 335144fdfc
commit 251274fc67
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

73
Codeforces/1698/C/C.cpp Normal file
View File

@ -0,0 +1,73 @@
#include <iostream>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e5 + 5;
int t, n, a[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
bool flag = true;
std::vector<long long> nums;
int cnt1 = 0, cnt2 = 0, cnt3 = 0;
cin >> n;
for (int i = 1, x; i <= n; i++) {
cin >> a[i];
if (a[i] < 0) cnt1++;
else if (a[i] > 0) cnt2++;
else cnt3++;
}
if (cnt1 > 2 || cnt2 > 2) {
cout << "No" << endl;
continue;
}
cnt3 = std::min(cnt3, 2);
for (int i = 1; i <= n; i++) {
if (a[i]) {
nums.push_back(a[i]);
}
}
for (int i = 1; i <= cnt3; i++) {
nums.push_back(0);
}
int q = nums.size();
for (int i = 0; i < q; i++) {
for (int j = i + 1; j < q; j++) {
for (int k = j + 1; k < q; k++) {
long long x = nums[i] + nums[j] + nums[k];
bool f = false;
for (int l = 0; l < q; l++) {
if (x == nums[l]) {
f = true;
break;
}
}
if (!f) flag = false;
}
}
}
cout << (flag ? "Yes" : "No") << endl;
}
return 0;
}