forked from ncduy0303/Competitive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpDiv2B_796.cpp
More file actions
111 lines (97 loc) · 1.85 KB
/
cpDiv2B_796.cpp
File metadata and controls
111 lines (97 loc) · 1.85 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
111
// First CP template
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
int convPow(int x)
{
int ans = 0;
while(x >0)
{
if ( x % 2 == 0 && x > 0)
{
ans +=1;
}
else
{
break;
}
x = x/2;
}
return ans;
}
int solve(int t[] , int y)
{
for(int i =0; i < y ; i++)
{
t[i] = convPow(t[i]);
}
vector<int> vect;
int min = 1000000000;
int freq = 0;
int finalAns = 0;
bool oddd = false;
for(int j = 0; j < y;j++)
{
if(t[j] > 0)
{
vect.push_back(t[j]);
if(t[j] < min )
{
min = t[j];
freq = 1;
}
else if(t[j] == min){
freq+=1;
}
else
{
}
}
else{
oddd = true;
}
}
if(!oddd){
if(vect.size() == 0)
{
finalAns = 0;
}
else
{
finalAns = (vect.size() - 1)+ min;
}
/*else {
int rem = vect.size() % freq ;
// finalAns = ((vect.size()/freq))*freq +min*(freq);
finalAns = (vect.size()/freq)*( rem) + ((vect.size()/freq) - 1)*(freq - rem) +min*(freq);
}*/
}
else {
finalAns = vect.size();
}
return finalAns;
}
int main() {
int tc ;
int alpha;
cin >> tc;
for (int t = 1; t <= tc; t++) {
int x;
cin >> x;
int testVal[x];
for(int i =0; i < x ; i++)
{
cin >> testVal[i];
}
cout << solve(testVal,x)<< endl;
// cout << "Case #" << t << ": ";
}
}