Skip to content

Commit 28bc324

Browse files
committed
practice
1 parent cee1558 commit 28bc324

File tree

15 files changed

+282
-0
lines changed

15 files changed

+282
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Contain file of my [competitive programming](https://en.wikipedia.org/wiki/Compe
44
- [Codechef](https://www.codechef.com/)
55
- [Hackerrank](https://www.hackerrank.com/)
66
- [Hackerearth](https://www.hackerearth.com/)
7+
- [Atcoder](https://atcoder.jp/home)
78
- [CSES](https://cses.fi/problemset/)
89
- [Facebook hacker cup](https://www.facebook.com/codingcompetitions/hacker-cup)
910

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
#include <ext/pb_ds/assoc_container.hpp>
7+
#include <ext/pb_ds/tree_policy.hpp>
8+
using namespace std;
9+
using namespace __gnu_pbds;
10+
typedef long long ll ;
11+
typedef vector<ll> vl;
12+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
13+
// define values.
14+
// #define mod 1000000007
15+
#define phi 1.618
16+
/* Abbrevations */
17+
#define ff first
18+
#define ss second
19+
#define mp make_pair
20+
#define line cout<<endl;
21+
#define pb push_back
22+
#define Endl "\n"
23+
// loops
24+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
25+
// Some print
26+
#define no cout<<"NO"<<endl;
27+
#define yes cout<<"YES"<<endl;
28+
// sort
29+
#define all(V) (V).begin(),(V).end()
30+
#define srt(V) sort(all(V))
31+
#define srtGreat(V) sort(all(V),greater<ll>())
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
// some extra
34+
#define sz(V) ll(V.size())
35+
/* ONLINE JUDGE */
36+
// #ifdef ONLINE_JUDGE
37+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
38+
// #endif
39+
// template
40+
template <typename T>
41+
T mymax(T x,T y)
42+
{
43+
return (x>y)?x:y;
44+
}
45+
// function
46+
47+
ll power(ll x,ll y,ll mod)
48+
{
49+
ll res=1;
50+
// x=x%mod;
51+
while(y>0)
52+
{
53+
if(y%2==1)
54+
{
55+
res*=x;
56+
// res=res%mod;
57+
}
58+
y/=2; x*=x; // x=x%mod;
59+
}
60+
return res;
61+
}
62+
ll str_to_num(string s)
63+
{
64+
return stoi(s);
65+
}
66+
67+
string num_to_str(ll num)
68+
{
69+
return to_string(num);
70+
}
71+
// datatype definination
72+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
73+
74+
/* ascii value
75+
A=65,Z=90,a=97,z=122
76+
*/
77+
/* -----------------------------------------------------------------------------------*/
78+
79+
ll solve()
80+
{
81+
string s;
82+
cin>>s;
83+
ll n=sz(s);
84+
if(n&1)
85+
{
86+
cout<<-1<<endl;
87+
return 0;
88+
}
89+
ll one=0,zero=0;
90+
for(auto x:s)
91+
{
92+
if(x=='0')
93+
zero++;
94+
else
95+
one++;
96+
}
97+
if(zero==n||one==n)
98+
{
99+
cout<<-1<<endl;
100+
return 0;
101+
}
102+
cout<<abs(one-zero)/2<<endl;
103+
return 0;
104+
}
105+
106+
int main()
107+
{
108+
speed;
109+
// freopen("input.txt","r",stdin);
110+
// freopen("output.txt","w",stdout);
111+
ll TestCase=1;
112+
cin>>TestCase;
113+
while(TestCase--)
114+
{
115+
solve();
116+
}
117+
}
118+
119+
/* stuff you should look before submission
120+
* int overflow
121+
* special test case (n=0||n=1||n=2)
122+
* don't get stuck on one approach if you get wrong answer
123+
*/

codechef/Div1/CookOff/COOK125A/a.out

35.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)