-
Notifications
You must be signed in to change notification settings - Fork 7
/
KURUK14.cpp
109 lines (108 loc) · 1.45 KB
/
KURUK14.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
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
#include<bits/stdc++.h>
int hs[1005];
int main()
{
// freopen("t.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
for(int i=0;i<1003;i++)
hs[i]=0;
int n;
scanf("%d",&n);
int arr[n+3];
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
hs[arr[i]]++;
}
if(n==2)
{
if(arr[0]==1&&arr[1]==1)
{
printf("YES\n");
}
else
printf("NO\n");
}
else
{
if(n%2==0)
{
bool flag=false;
if(hs[n-1]==2)
{
for(int i=1;i<=n-2;i++)
{
if(hs[i]==1||hs[i]==2)
{
//printf("fd");
if(hs[i]==1)
{
if(hs[n-1-i]!=1)
{
flag=true;
printf("NO\n");
break;
}
}
else if(hs[i]==2)
{
// printf("fd");
if(hs[n-1-i]!=0)
{
// printf("fd");
flag=true;
printf("NO\n");
break;
}
}
}
}
if(!flag)
printf("YES\n");
}
else
printf("NO\n");
}
else
{
bool flag=false;
int mid=n/2;
if(hs[n-1]==2&&hs[mid]==1)
{
for(int i=1;i<=n-2;i++)
{
if(hs[i]==1||hs[i]==2)
{
if(hs[i]==1)
{
if(hs[n-1-i]!=1)
{
flag=true;
printf("NO\n");
break;
}
}
else if(hs[i]==2)
{
if(hs[n-1-i]!=0)
{
flag=true;
printf("NO\n");
break;
}
}
}
}
if(flag==false)
printf("YES\n");
}
else
{
printf("NO\n");
}
}
}
}