Skip to content

Commit 0ec96f1

Browse files
committed
contests solution
1 parent ebc0461 commit 0ec96f1

File tree

7 files changed

+802
-0
lines changed

7 files changed

+802
-0
lines changed

Codechef/CLOSEVOWEL.cpp

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 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+
vector<char> v={'a','e','i','o','u'};
75+
ll n;
76+
string s;
77+
cin>>n>>s;
78+
ll ans=1;
79+
for(auto x:s){
80+
if(x=='a'||x=='e'||x=='i'||x=='o'||x=='u'){
81+
continue;
82+
}
83+
else{
84+
ll mini=INF,count=0;
85+
for(auto y:v){
86+
ll dist=abs(x-y);
87+
mini=min(mini,dist);
88+
}
89+
for(auto y:v){
90+
ll dist=abs(x-y);
91+
if(dist==mini){
92+
count++;
93+
}
94+
}
95+
ans=(ans*count)%mod1;
96+
}
97+
}
98+
cout<<ans<<endl;
99+
100+
return 0;
101+
}
102+
int main(){
103+
speed;
104+
/*
105+
#ifndef ONLINE_JUDGE
106+
freopen("input.txt","r",stdin);
107+
freopen("output.txt","w",stdout);
108+
#endif
109+
*/
110+
ll TestCase=1;
111+
cin>>TestCase;
112+
while(TestCase--){
113+
solve();
114+
}
115+
}
116+
/* -----------------END OF PROGRAM --------------------*/
117+
/*
118+
* stuff you should look before submission
119+
* constraint and time limit
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/COMPRESSVD.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
vl v(n);
77+
for(ll i=0;i<n;i++){
78+
cin>>v[i];
79+
}
80+
ll pre=0,ans=0;
81+
for(ll i=0;i<n;i++){
82+
if(i==0){
83+
pre=v[i];
84+
}
85+
ll j=i+1;
86+
while(j<n && v[j]==v[i]){
87+
j++;
88+
}
89+
i=j-1;
90+
ans++;
91+
pre=v[i];
92+
}
93+
cout<<ans<<endl;
94+
return 0;
95+
}
96+
int main(){
97+
speed;
98+
/*
99+
#ifndef ONLINE_JUDGE
100+
freopen("input.txt","r",stdin);
101+
freopen("output.txt","w",stdout);
102+
#endif
103+
*/
104+
ll TestCase=1;
105+
cin>>TestCase;
106+
while(TestCase--){
107+
solve();
108+
}
109+
}
110+
/* -----------------END OF PROGRAM --------------------*/
111+
/*
112+
* stuff you should look before submission
113+
* constraint and time limit
114+
* int overflow
115+
* special test case (n=0||n=1||n=2)
116+
* don't get stuck on one approach if you get wrong answer
117+
*/

Codechef/ESUBXOR.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
vl a(n),b(n);
77+
ll suru=pow(2,1);
78+
for(ll i=0;i<n;i++){
79+
a[i]=suru++;
80+
}
81+
if(n&1){
82+
suru++;
83+
}
84+
85+
for(ll i=0;i<n;i++){
86+
b[i]=suru++;
87+
}
88+
printv(a);
89+
printv(b);
90+
91+
return 0;
92+
}
93+
int main(){
94+
speed;
95+
/*
96+
#ifndef ONLINE_JUDGE
97+
freopen("input.txt","r",stdin);
98+
freopen("output.txt","w",stdout);
99+
#endif
100+
*/
101+
ll TestCase=1;
102+
cin>>TestCase;
103+
while(TestCase--){
104+
solve();
105+
}
106+
}
107+
/* -----------------END OF PROGRAM --------------------*/
108+
/*
109+
* stuff you should look before submission
110+
* constraint and time limit
111+
* int overflow
112+
* special test case (n=0||n=1||n=2)
113+
* don't get stuck on one approach if you get wrong answer
114+
*/

0 commit comments

Comments
 (0)