Skip to content

Commit f4a588e

Browse files
committed
contest solution
1 parent 70c9a46 commit f4a588e

11 files changed

+1315
-0
lines changed

Codechef/CHFMIST.cpp

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
typedef vector<vector<ll>> vvl;
13+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
14+
/* Abbrevations */
15+
#define ff first
16+
#define ss second
17+
#define mp make_pair
18+
#define line cout<<endl;
19+
#define pb push_back
20+
// Some print
21+
#define no cout<<"NO"<<endl;
22+
#define yes cout<<"YES"<<endl;
23+
// sort
24+
#define all(V) (V).begin(),(V).end()
25+
#define srt(V) sort(all(V))
26+
#define srtGreat(V) sort(all(V),greater<ll>())
27+
// some extra
28+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
29+
#define precision(x) cout<<fixed<<setprecision(x);
30+
#define sz(V) ll(V.size())
31+
// datatype definination
32+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
33+
34+
35+
class Codeforces{
36+
private:
37+
// read only variable
38+
const ll INF=1e18;
39+
const ll mod1=1e9+7;
40+
const ll mod2=998244353;
41+
42+
43+
public:
44+
Codeforces(){
45+
46+
}
47+
48+
ll power(ll x,ll y){
49+
ll result=1;
50+
while(y>0){
51+
if(y&1){
52+
result*=x;
53+
}
54+
y>>=1;
55+
x*=x;
56+
}
57+
return result;
58+
}
59+
60+
ll power(ll x,ll y,ll mod){
61+
ll result=1;
62+
x%=mod;
63+
while(y>0){
64+
if(y&1){
65+
result*=x;
66+
result%=mod;
67+
}
68+
y>>=1;
69+
x*=x;
70+
x%=mod;
71+
}
72+
return result;
73+
}
74+
75+
ll str_to_num(string s){
76+
stringstream pk(s);
77+
ll num;
78+
pk>>num;
79+
return num;
80+
}
81+
82+
string num_to_str(ll num){
83+
return to_string(num);
84+
}
85+
// Techniques :
86+
// divide into cases, brute force, pattern finding
87+
// sort, greedy, binary search, two pointer
88+
// transform into graph
89+
90+
// Experience :
91+
// Cp is nothing but only observation and mathematics.
92+
ll solve(){
93+
ll n;
94+
cin>>n;
95+
vector<ll> v(n);
96+
ll sum=0;
97+
for(ll i=0;i<n;i++){
98+
cin>>v[i];
99+
sum+=v[i];
100+
}
101+
sum*=2;
102+
if(sum%n){
103+
cout<<0<<endl;
104+
return 0;
105+
}
106+
else{
107+
ll temp=sum/n;
108+
map<ll,ll> m;
109+
ll no_of_way=0;
110+
for(ll i=0;i<n;i++){
111+
no_of_way+=m[temp-v[i]];
112+
m[v[i]]++;
113+
}
114+
cout<<no_of_way<<endl;
115+
}
116+
return 0;
117+
}
118+
};
119+
120+
121+
/* --------------------MAIN PROGRAM----------------------------*/
122+
123+
int main()
124+
{
125+
speed;
126+
/* #ifndef ONLINE_JUDGE
127+
freopen("input.txt","r",stdin);
128+
freopen("output.txt","w",stdout);
129+
#endif */
130+
ll TestCase=1;
131+
cin>>TestCase;
132+
while(TestCase--){
133+
Codeforces cf;
134+
cf.solve();
135+
}
136+
}
137+
/* -----------------END OF PROGRAM --------------------*/
138+
/*
139+
* stuff you should look before submission
140+
* constraint and time limit
141+
* int overflow
142+
* special test case (n=0||n=1||n=2)
143+
* don't get stuck on one approach if you get wrong answer
144+
*/

Codechef/GMINEQ.cpp

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
typedef vector<vector<ll>> vvl;
13+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
14+
/* Abbrevations */
15+
#define ff first
16+
#define ss second
17+
#define mp make_pair
18+
#define line cout<<endl;
19+
#define pb push_back
20+
// Some print
21+
#define no cout<<"NO"<<endl;
22+
#define yes cout<<"YES"<<endl;
23+
// sort
24+
#define all(V) (V).begin(),(V).end()
25+
#define srt(V) sort(all(V))
26+
#define srtGreat(V) sort(all(V),greater<ll>())
27+
// some extra
28+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
29+
#define precision(x) cout<<fixed<<setprecision(x);
30+
#define sz(V) ll(V.size())
31+
// datatype definination
32+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
33+
34+
35+
class Codeforces{
36+
private:
37+
// read only variable
38+
const ll INF=1e18;
39+
const ll mod1=1e9+7;
40+
const ll mod2=998244353;
41+
42+
43+
public:
44+
Codeforces(){
45+
46+
}
47+
48+
ll power(ll x,ll y){
49+
ll result=1;
50+
while(y>0){
51+
if(y&1){
52+
result*=x;
53+
}
54+
y>>=1;
55+
x*=x;
56+
}
57+
return result;
58+
}
59+
60+
ll power(ll x,ll y,ll mod){
61+
ll result=1;
62+
x%=mod;
63+
while(y>0){
64+
if(y&1){
65+
result*=x;
66+
result%=mod;
67+
}
68+
y>>=1;
69+
x*=x;
70+
x%=mod;
71+
}
72+
return result;
73+
}
74+
75+
ll str_to_num(string s){
76+
stringstream pk(s);
77+
ll num;
78+
pk>>num;
79+
return num;
80+
}
81+
82+
string num_to_str(ll num){
83+
return to_string(num);
84+
}
85+
// Techniques :
86+
// divide into cases, brute force, pattern finding
87+
// sort, greedy, binary search, two pointer
88+
// transform into graph
89+
90+
// Experience :
91+
// Cp is nothing but only observation and mathematics.
92+
ll solve(){
93+
ll n;
94+
cin>>n;
95+
ll one=0,minus_one=0;
96+
for(ll i=0;i<n;i++){
97+
ll x;
98+
cin>>x;
99+
if(x==1){
100+
one++;
101+
}
102+
else{
103+
minus_one++;
104+
}
105+
}
106+
ll maxo=max(one,minus_one);
107+
ll mini=min(one,minus_one);
108+
ll diff=mini/2;
109+
diff*=2;
110+
mini-=diff;
111+
maxo-=diff;
112+
if(mini==0 || mini==1){
113+
if(maxo<=2){
114+
yes
115+
return 0;
116+
}
117+
else{
118+
no
119+
return 0;
120+
}
121+
}
122+
no
123+
return 0;
124+
}
125+
};
126+
127+
128+
/* --------------------MAIN PROGRAM----------------------------*/
129+
130+
int main()
131+
{
132+
speed;
133+
/* #ifndef ONLINE_JUDGE
134+
freopen("input.txt","r",stdin);
135+
freopen("output.txt","w",stdout);
136+
#endif */
137+
ll TestCase=1;
138+
cin>>TestCase;
139+
while(TestCase--){
140+
Codeforces cf;
141+
cf.solve();
142+
}
143+
}
144+
/* -----------------END OF PROGRAM --------------------*/
145+
/*
146+
* stuff you should look before submission
147+
* constraint and time limit
148+
* int overflow
149+
* special test case (n=0||n=1||n=2)
150+
* don't get stuck on one approach if you get wrong answer
151+
*/

0 commit comments

Comments
 (0)