forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB0082.cpp
More file actions
47 lines (43 loc) · 768 Bytes
/
B0082.cpp
File metadata and controls
47 lines (43 loc) · 768 Bytes
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
// Problem Code: ICPC16B
#include <iostream>
#include <vector>
using namespace std;
string beautifulArrays(vector<int> a) {
if(a.size() == 1)
return "yes";
int zeros, posOnes, negOnes, other;
zeros = posOnes = negOnes = other = 0;
for(int i=0 ; i<a.size() ; i++)
switch(a[i]) {
case 0:
zeros++;
break;
case 1:
posOnes++;
break;
case -1:
negOnes++;
break;
default:
other++;
}
if( (other>1) || (other == 1 && negOnes > 0) || (negOnes > 1 && posOnes == 0) )
return "no";
else
return "yes";
}
int main() {
int T, n, num;
vector<int> a;
cin >> T;
while(T--) {
cin >> n;
for(int i=0 ; i<n ; i++) {
cin >> num;
a.push_back(num);
}
cout << beautifulArrays(a) << endl;
a.clear();
}
return 0;
}