Skip to content

Commit c1712a3

Browse files
committed
contest solution
1 parent 037187c commit c1712a3

14 files changed

+1617
-12
lines changed

Codechef/LOOP.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 unsigned long long ull;
12+
typedef vector<ll> vl;
13+
typedef vector<vector<ll>> vvl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
// loops
22+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
23+
// Some print
24+
#define no cout<<"NO"<<endl;
25+
#define yes cout<<"YES"<<endl;
26+
// sort
27+
#define all(V) (V).begin(),(V).end()
28+
#define srt(V) sort(all(V))
29+
#define srtGreat(V) sort(all(V),greater<ll>())
30+
// some extra
31+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} cout<<endl;
32+
#define precision(x) cout<<fixed<<setprecision(x);
33+
#define sz(V) ll(V.size())
34+
// function
35+
ll power(ll x,ll y,ll mod)
36+
{
37+
ll res=1;
38+
// x=x%mod;
39+
while(y>0){
40+
if(y%2==1){
41+
res*=x;
42+
// res=res%mod;
43+
}
44+
y/=2; x*=x; // x=x%mod;
45+
}
46+
return res;
47+
}
48+
ll str_to_num(string s){
49+
return stoi(s);
50+
}
51+
string num_to_str(ll num){
52+
return to_string(num);
53+
}
54+
/* ascii value
55+
A=65,Z=90,a=97,z=122
56+
*/
57+
/* Some syntax
58+
//Syntax to create a min heap for priority queue
59+
//priority_queue <int, vector<int>, greater<int>>pq;
60+
*/
61+
/* --------------------MAIN PROGRAM----------------------------*/
62+
const ll INF=1e18;
63+
const ll mod1=1e9+7;
64+
const ll mod2=998244353;
65+
// Techniques :
66+
// divide into cases, brute force, pattern finding
67+
// sort, greedy, binary search, two pointer
68+
// transform into graph
69+
70+
71+
// Experience :
72+
// Cp is nothing but only observation and mathematics.
73+
ll solve(){
74+
ll a,b,m;
75+
cin>>a>>b>>m;
76+
ll temp=abs(a-b);
77+
cout<<min(temp,m-temp)<<endl;
78+
return 0;
79+
}
80+
int main(){
81+
speed;
82+
/*
83+
#ifndef ONLINE_JUDGE
84+
freopen("input.txt","r",stdin);
85+
freopen("output.txt","w",stdout);
86+
#endif
87+
*/
88+
ll TestCase=1;
89+
cin>>TestCase;
90+
while(TestCase--){
91+
solve();
92+
}
93+
}
94+
/* -----------------END OF PROGRAM --------------------*/
95+
/*
96+
* stuff you should look before submission
97+
* constraint and time limit
98+
* int overflow
99+
* special test case (n=0||n=1||n=2)
100+
* don't get stuck on one approach if you get wrong answer
101+
*/

Codechef/PUSH7PA.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 unsigned long long ull;
12+
typedef vector<ll> vl;
13+
typedef vector<vector<ll>> vvl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
// loops
22+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
23+
// Some print
24+
#define no cout<<"NO"<<endl;
25+
#define yes cout<<"YES"<<endl;
26+
// sort
27+
#define all(V) (V).begin(),(V).end()
28+
#define srt(V) sort(all(V))
29+
#define srtGreat(V) sort(all(V),greater<ll>())
30+
// some extra
31+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} cout<<endl;
32+
#define precision(x) cout<<fixed<<setprecision(x);
33+
#define sz(V) ll(V.size())
34+
// function
35+
ll power(ll x,ll y,ll mod)
36+
{
37+
ll res=1;
38+
// x=x%mod;
39+
while(y>0){
40+
if(y%2==1){
41+
res*=x;
42+
// res=res%mod;
43+
}
44+
y/=2; x*=x; // x=x%mod;
45+
}
46+
return res;
47+
}
48+
ll str_to_num(string s){
49+
return stoi(s);
50+
}
51+
string num_to_str(ll num){
52+
return to_string(num);
53+
}
54+
/* ascii value
55+
A=65,Z=90,a=97,z=122
56+
*/
57+
/* Some syntax
58+
//Syntax to create a min heap for priority queue
59+
//priority_queue <int, vector<int>, greater<int>>pq;
60+
*/
61+
/* --------------------MAIN PROGRAM----------------------------*/
62+
const ll INF=1e18;
63+
const ll mod1=1e9+7;
64+
const ll mod2=998244353;
65+
// Techniques :
66+
// divide into cases, brute force, pattern finding
67+
// sort, greedy, binary search, two pointer
68+
// transform into graph
69+
70+
71+
// Experience :
72+
// Cp is nothing but only observation and mathematics.
73+
ll solve(){
74+
ll n;
75+
cin>>n;
76+
ll max_height = 0;
77+
map<ll,ll> mp;
78+
for(ll i=0;i<n;i++){
79+
ll temp;
80+
cin>>temp;
81+
mp[temp]++;
82+
}
83+
for(auto x:mp){
84+
max_height = max(max_height,x.ff+x.ss-1);
85+
}
86+
cout<<max_height<<endl;
87+
return 0;
88+
}
89+
int main(){
90+
speed;
91+
/*
92+
#ifndef ONLINE_JUDGE
93+
freopen("input.txt","r",stdin);
94+
freopen("output.txt","w",stdout);
95+
#endif
96+
*/
97+
ll TestCase=1;
98+
cin>>TestCase;
99+
while(TestCase--){
100+
solve();
101+
}
102+
}
103+
/* -----------------END OF PROGRAM --------------------*/
104+
/*
105+
* stuff you should look before submission
106+
* constraint and time limit
107+
* int overflow
108+
* special test case (n=0||n=1||n=2)
109+
* don't get stuck on one approach if you get wrong answer
110+
*/

Codechef/QUEENATTACK.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 unsigned long long ull;
12+
typedef vector<ll> vl;
13+
typedef vector<vector<ll>> vvl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
// loops
22+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
23+
// Some print
24+
#define no cout<<"No"<<endl;
25+
#define yes cout<<"Yes"<<endl;
26+
// sort
27+
#define all(V) (V).begin(),(V).end()
28+
#define srt(V) sort(all(V))
29+
#define srtGreat(V) sort(all(V),greater<ll>())
30+
// some extra
31+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} cout<<endl;
32+
#define precision(x) cout<<fixed<<setprecision(x);
33+
#define sz(V) ll(V.size())
34+
// function
35+
ll power(ll x,ll y,ll mod)
36+
{
37+
ll res=1;
38+
// x=x%mod;
39+
while(y>0){
40+
if(y%2==1){
41+
res*=x;
42+
// res=res%mod;
43+
}
44+
y/=2; x*=x; // x=x%mod;
45+
}
46+
return res;
47+
}
48+
ll str_to_num(string s){
49+
return stoi(s);
50+
}
51+
string num_to_str(ll num){
52+
return to_string(num);
53+
}
54+
/* ascii value
55+
A=65,Z=90,a=97,z=122
56+
*/
57+
/* Some syntax
58+
//Syntax to create a min heap for priority queue
59+
//priority_queue <int, vector<int>, greater<int>>pq;
60+
*/
61+
/* --------------------MAIN PROGRAM----------------------------*/
62+
const ll INF=1e18;
63+
const ll mod1=1e9+7;
64+
const ll mod2=998244353;
65+
// Techniques :
66+
// divide into cases, brute force, pattern finding
67+
// sort, greedy, binary search, two pointer
68+
// transform into graph
69+
70+
71+
// Experience :
72+
// Cp is nothing but only observation and mathematics.
73+
ll solve(){
74+
ll n,x,y;
75+
cin>>n>>x>>y;
76+
// same row and same column
77+
ll ans=n-1+n-1;
78+
// all four diagonal
79+
ans+=min(x-1,y-1)+min(x-1,n-y)+min(n-x,y-1)+min(n-x,n-y);
80+
cout<<ans<<endl;
81+
return 0;
82+
}
83+
int main(){
84+
speed;
85+
/*
86+
#ifndef ONLINE_JUDGE
87+
freopen("input.txt","r",stdin);
88+
freopen("output.txt","w",stdout);
89+
#endif
90+
*/
91+
ll TestCase=1;
92+
cin>>TestCase;
93+
while(TestCase--){
94+
solve();
95+
}
96+
}
97+
/* -----------------END OF PROGRAM --------------------*/
98+
/*
99+
* stuff you should look before submission
100+
* constraint and time limit
101+
* int overflow
102+
* special test case (n=0||n=1||n=2)
103+
* don't get stuck on one approach if you get wrong answer
104+
*/

0 commit comments

Comments
 (0)