Skip to content

Commit d0e68b9

Browse files
committed
Codechef problem solutions
1 parent 0d2fe88 commit d0e68b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3041
-0
lines changed

Codechef solutions/ADAKING.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <stdio.h>
2+
int main(void) {
3+
int t,n,k,r,i,j;
4+
scanf("%d",&t);
5+
while(t--){
6+
scanf("%d",&k);
7+
r=64-k;
8+
for(i=1;i<=8;i++){
9+
for(j=1;j<=8;j++){
10+
if(i==8&&j==8)
11+
{printf("O");}
12+
else if(r)
13+
{printf("X");r--;}
14+
else
15+
{ printf(".");}
16+
}
17+
printf("\n");
18+
}
19+
}
20+
return 0;
21+
}
22+

Codechef solutions/ALPHABET.c

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//Author: Rakshit Naidu
2+
3+
#include <stdio.h>
4+
5+
int main(void) {
6+
// your code goes here
7+
char s[30],str[15];
8+
scanf("%s",&s);
9+
int x = strlen(s);
10+
int t;
11+
scanf("%d",&t);
12+
13+
while(t--)
14+
{
15+
scanf("%s",&str);
16+
int i,j;
17+
int l=strlen(str);
18+
for(i=0;i<strlen(str);i++)
19+
{
20+
for(j=0;j<strlen(s);j++)
21+
{
22+
if(str[i]==s[j])
23+
{
24+
break;
25+
}
26+
}
27+
if(j>=strlen(s))
28+
{
29+
printf("No\n");
30+
break;
31+
}
32+
}
33+
if(i>=strlen(str))
34+
{
35+
printf("Yes\n");
36+
}
37+
}
38+
39+
return 0;
40+
}
41+

Codechef solutions/BIGSALE .cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//BIGSALE - codechef
2+
3+
#include <iostream>
4+
#include<bits/stdc++.h>
5+
using namespace std;
6+
7+
int main()
8+
{
9+
//cout << "Hello world!" << endl;
10+
int t;
11+
cin>>t;
12+
while(t--){
13+
int n;
14+
cin>>n;
15+
double q[n];
16+
double p[n],x[n],l=0;
17+
for(int i=0;i<n;i++){
18+
cin>>p[i]>>q[i]>>x[i];
19+
l=l+(p[i]*x[i]*x[i]*q[i]*0.0001);
20+
}
21+
cout<<fixed<<setprecision(10)<<l<<endl;
22+
}
23+
return 0;
24+
}
25+

Codechef solutions/BIT2B.cpp

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#include<bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
6+
#define MAX 1000000
7+
#define ll long long
8+
#define db double
9+
#define str string
10+
#define pb push_back
11+
#define For(i,s,e) for (ll i=(s); i<(e); i++)
12+
#define Forrev(i,s,e) for (ll i=(s); i>=(e); i--)
13+
#define all(v) v.begin(),v.end()
14+
15+
#define vll vector<ll>
16+
#define vs vector<string>
17+
#define mapll map<ll,ll>
18+
#define pll pair<ll,ll>
19+
#define initialise(a, x) memset(a, x, sizeof(a))
20+
#define maxheap priority_queue<ll>
21+
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
22+
23+
#define ff first
24+
#define ss second
25+
#define endl "\n"
26+
#define mp make_pair
27+
const ll mod=1e9 + 7;
28+
29+
ll takemod(ll a) {
30+
return ((a%mod)+mod)%mod;
31+
}
32+
33+
ll gcd(ll a, ll b) {
34+
if (b == 0)
35+
return a;
36+
return gcd(b, a % b);
37+
}
38+
39+
ll fast_exp(ll base, ll expo) {
40+
ll res=1;
41+
while(expo>0) {
42+
if(expo&1) res=(res*base)%mod;
43+
base=(base*base)%mod;
44+
expo>>=1;}
45+
return res;
46+
}
47+
48+
ll modinv(ll a) {
49+
return takemod(fast_exp(takemod(a), mod-2));
50+
}
51+
52+
53+
signed main()
54+
{
55+
fast_cin();
56+
#ifndef ONLINE_JUDGE
57+
freopen("C:/IO/in.txt", "r", stdin);
58+
freopen("C:/IO/out.txt", "w", stdout);
59+
#endif
60+
ll t,n;
61+
cin>>t;
62+
For(l,0,t)
63+
{
64+
cin>>n;
65+
ll arr[n];
66+
For(i,0,n)
67+
{
68+
cin>>arr[i];
69+
}
70+
71+
ll x;
72+
cin>>x;
73+
74+
ll i=0,j=n-1,sum1=0,sum2=0;
75+
ll sumarr[n];
76+
memset(sumarr,0,sizeof(sumarr));
77+
78+
ll markarr[n];
79+
memset(markarr,-1,sizeof(markarr));
80+
81+
while(i<=j)
82+
{
83+
if(i==j)
84+
{
85+
if(markarr[i]!=-1)
86+
break;
87+
ll ans1=0,ans2=0;
88+
For(k,0,n)
89+
{
90+
//cout<<markarr[i]<<endl;
91+
if(markarr[k]==1)
92+
ans1++;
93+
else if(markarr[k]==2)
94+
ans2++;
95+
}
96+
//cout<<ans1<<"XX"<<ans2<<endl;
97+
if(ans1>=ans2)
98+
{
99+
markarr[i]=1;
100+
i++;
101+
}
102+
else
103+
{
104+
markarr[i]=2;
105+
j--;
106+
}
107+
}
108+
else
109+
{
110+
sum1=0,sum2=0;
111+
sum2=arr[j];
112+
markarr[j]=2;
113+
while(i<j and sum1<x*sum2)
114+
{
115+
if(sum1+arr[i]-sumarr[i]>x*sum2)
116+
{
117+
sumarr[i]+=x*sum2-sum1;
118+
sum1=sum2;
119+
markarr[i]=1;
120+
if(sumarr[i]==arr[i])
121+
i++;
122+
break;
123+
}
124+
else
125+
{
126+
sum1+=arr[i]-sumarr[i];
127+
markarr[i]=1;
128+
i++;
129+
}
130+
}
131+
j--;
132+
//cout<<i<<" "<<j<<endl;
133+
134+
}
135+
136+
}
137+
138+
ll ans1=0,ans2=0;
139+
For(k,0,n)
140+
{
141+
//cout<<markarr[k]<<" ";
142+
if(markarr[k]==1)
143+
ans1++;
144+
else if(markarr[k]==2)
145+
ans2++;
146+
}
147+
cout<<ans1<<" "<<ans2<<endl;
148+
}
149+
150+
return 0;
151+
}

Codechef solutions/BRLADDER.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
//important constants
5+
#define pi M_PI
6+
#define mod 1000000007
7+
#define maX(a,b) ((a)>(b)?(a):(b))
8+
#define miN(a,b) ((a)<(b)?(a):(b))
9+
10+
#ifdef ONLINE_JUDGE
11+
#define MAX 200005
12+
#else
13+
#define MAX 100000
14+
#endif
15+
16+
int a[MAX],b[MAX];
17+
char s[MAX],r[MAX];
18+
int test;
19+
20+
int main(){
21+
#ifndef ONLINE_JUDGE
22+
freopen("input.txt","r",stdin);
23+
// freopen("output.txt","w",stdout);
24+
#endif
25+
26+
int t,n,m,k,l,x,y,z,flag,count,d,mx,mn;
27+
long long int sum,prod;
28+
29+
scanf("%d",&test);
30+
31+
while(test--){
32+
flag=0;
33+
// scanf("%d",&n);
34+
scanf("%d%d",&n,&m);
35+
36+
if(n%2 && m%2){
37+
if(abs(n-m)==2)
38+
flag=1;
39+
}else if(n%2){
40+
if(m-n==1)
41+
flag=1;
42+
}else if(m%2){
43+
if(n-m==1)
44+
flag=1;
45+
}else{
46+
if(abs(n-m)==2)
47+
flag=1;
48+
}
49+
if(flag) printf("YES\n");
50+
else printf("NO\n");
51+
52+
}
53+
return 0;
54+
}

Codechef solutions/CANDY123.c

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//Author: Rakshit Naidu
2+
3+
#include <stdio.h>
4+
int func(int x,int y,int r);
5+
6+
int main(void) {
7+
// your code goes here
8+
int t;
9+
scanf("%d",&t);
10+
11+
while(t--)
12+
{
13+
int a,b;
14+
scanf("%d %d",&a,&b);
15+
int rem=2;
16+
func(a,b,rem);
17+
}
18+
return 0;
19+
}
20+
int func(int x,int y,int r)
21+
{
22+
x = x - (r/2);
23+
r++;
24+
r++;
25+
if(x<0)
26+
{
27+
printf("Bob\n");
28+
return;
29+
}
30+
y = y - (r/2);
31+
r++;
32+
r++;
33+
if(y<0)
34+
{
35+
printf("Limak\n");
36+
return;
37+
}
38+
return func(x,y,r);
39+
}

Codechef solutions/CHCHCL.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//Author: Rakshit Naidu
2+
3+
#include <stdio.h>
4+
5+
int main(void) {
6+
// your code goes here
7+
int t;
8+
scanf("%d",&t);
9+
10+
while(t--)
11+
{
12+
int m,n;
13+
scanf("%d %d",&m,&n);
14+
15+
if(m%2==0||n%2==0)
16+
{
17+
printf("Yes\n");
18+
}
19+
else
20+
{
21+
printf("No\n");
22+
}
23+
}
24+
return 0;
25+
}
26+

0 commit comments

Comments
 (0)