-
Notifications
You must be signed in to change notification settings - Fork 0
/
C. Beautiful Regional Contest.cpp
94 lines (93 loc) · 2.12 KB
/
C. Beautiful Regional Contest.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
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,i;
cin>>n;
ll arr[n+10],g_req,g=1,b=0,s=0,flag=0,pos,p,fl=0;
for(i=1;i<=n;i++)
cin>>arr[i];
if(n<5)
{
cout<<"0 0 0"<<endl;
continue;
}
g_req=(n/3)-1;
for(i=1;i<n;i++)
{
if(arr[i]==arr[i+1])
g++;
else
break;
}
if(g>g_req)
{
cout<<"0 0 0"<<endl;
continue;
}
if(arr[n/2]==arr[(n/2)+1])
{
for(i=n/2;i>g;i--)
if(arr[i]!=arr[i-1])
{
pos=i-1;
flag=1;
break;
}
if(flag)
for(i=pos;i>g;i--)
{
if(arr[i]==arr[i-1])
b++;
else
{
b++;
if(b>g)
{
p=i;
fl=1;
break;
}
}
if(fl)
break;
}
}
else
for(i=n/2;i>=g;i--)
{
if(arr[i]!=arr[i-1])
{
b++;
if(b>g)
{
p=i;
fl=1;
}
flag=1;
}
else
b++;
if(fl)
break;
}
if(flag==0 || fl==0)
{
cout<<"0 0 0"<<endl;
continue;
}
s=p-g-1;
if(s==0 || (g>=b) || (g>=s))
{
cout<<"0 0 0"<<endl;
continue;
}
cout<<g<<" "<<s<<" "<<b<<endl;
}
return 0;
}