-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyetanothertetrisproblem.cpp
More file actions
110 lines (103 loc) · 1.64 KB
/
yetanothertetrisproblem.cpp
File metadata and controls
110 lines (103 loc) · 1.64 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include<bits/stdc++.h>
using namespace std;
// https://codeforces.com/contest/1324/problem/A
typedef long long ll;
bool areAllOdd(int a[],int n)
{
for(int i=0;i<n;i++)
{
if(a[i]%2==0 and a[i]!=0)
{
return false;
}
}
return true;
}
bool arePositive(int a[],int n)
{
for(int i=0;i<n;i++)
{
if(a[i]<=0)
{
return false;
}
}
return true;
}
bool areAllEqual(int a[],int n)
{
for(int i=1;i<n;i++)
{
if(a[i]!=a[0])
{
return false;
}
}
return true;
}
int smallestIdx(int a[],int n)
{
int idx=0;
for(int i=1;i<n;i++)
{
if(a[i]<a[idx])
{
idx=i;
}
}
return idx;
}
bool canClear(int a[],int n)
{
if(n<=1 or areAllEqual(a,n))
{
return true;
}
int small=smallestIdx(a,n);
a[small]+=2;
small=smallestIdx(a,n);
int diff=a[small];
for(int i=0;i<n;i++)
{
a[i]-=diff;
}
while(!arePositive(a,n))
{
int small=smallestIdx(a,n);
a[small]+=2;
}
small=smallestIdx(a,n);
diff=a[small];
for(int i=0;i<n;i++)
{
a[i]-=diff;
}
if(areAllEqual(a,n))
{
return true;
}
if(areAllOdd(a,n))
{
return false;
}
return canClear(a,n);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<(canClear(a,n)?"YES":"NO")<<endl;
}
return 0;
}