-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uploaded CodeChef Contests' accepted submissions
- Loading branch information
1 parent
987515c
commit 8f2d6cd
Showing
12 changed files
with
628 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include<bits/stdc++.h> | ||
#define yes cout<<"Yes"<<"\n" | ||
#define no cout<<"No"<<"\n" | ||
#define ent cout<<"\n"; | ||
#define endl "\n" | ||
#define int long long | ||
using ll=long long; | ||
using namespace std; | ||
|
||
void solve() | ||
{ | ||
int n; | ||
cin>>n; | ||
if(n&1) | ||
{ | ||
cout<<-1; | ||
return; | ||
} | ||
for(int i=0;i<n;i++) | ||
{ | ||
cout<<i<<" "; | ||
} | ||
cout<<"\n"; | ||
for(int i=1;i<n;i++) | ||
{ | ||
if(i&1) | ||
{ | ||
for(int j=n-i;j>=0;j--) | ||
{ | ||
cout<<j<<" "; | ||
} | ||
for(int j=n-1;j>n-i;j--) | ||
{ | ||
cout<<j<<" "; | ||
} | ||
} | ||
else | ||
{ | ||
for(int j=n-i;j<n;j++) | ||
{ | ||
cout<<j<<" "; | ||
} | ||
for(int j=0;j<n-i;j++) | ||
{ | ||
cout<<j<<" "; | ||
} | ||
} | ||
cout<<"\n"; | ||
} | ||
string first="",second="",up=""; | ||
for(int i=1;i<=n-2;i++) | ||
{ | ||
first+="R"; | ||
second+="L"; | ||
up+="U"; | ||
} | ||
cout<<first+"RD"; | ||
for(int i=1;i<n-1;i++) | ||
{ | ||
if(i&1) | ||
{ | ||
cout<<second+"D"; | ||
} | ||
else | ||
{ | ||
cout<<first+"D"; | ||
} | ||
} | ||
cout<<second+"L"; | ||
cout<<up+"U"<<"\n"; | ||
} | ||
|
||
int32_t main() | ||
{ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
solve(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include<bits/stdc++.h> | ||
#define yes cout<<"Yes"<<"\n" | ||
#define no cout<<"No"<<"\n" | ||
#define endl "\n" | ||
#define int long long | ||
using ll=long long; | ||
using namespace std; | ||
|
||
void solve() | ||
{ | ||
int n; | ||
cin>>n; | ||
if(n&1) | ||
{ | ||
cout<<2<<" "<<2<<" "<<(n-4)<<"\n"; | ||
return; | ||
} | ||
cout<<2<<" "<<(n-2)/2<<" "<<(n-2)/2<<"\n"; | ||
return; | ||
} | ||
|
||
int32_t main() | ||
{ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
int t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
solve(); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include<bits/stdc++.h> | ||
#define yes cout<<"Yes"<<"\n" | ||
#define no cout<<"No"<<"\n" | ||
#define endl "\n" | ||
#define int long long | ||
using ll=long long; | ||
using namespace std; | ||
|
||
bool isp(int n) | ||
{ | ||
for(int i=2;i*i<=n;i++) | ||
{ | ||
if(n%i==0) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
vector<vector<int>>vec={{3,4,1,2},{4,5,1,2,3},{4,5,6,1,2,3},{6,7,1,2,3,4,5}}; | ||
|
||
void solve() | ||
{ | ||
int n; | ||
cin>>n; | ||
if(n<=3) | ||
{ | ||
cout<<-1; | ||
return; | ||
} | ||
int t=n/4-1,i=0; | ||
while(i<t) | ||
{ | ||
for(auto j:vec[0]) | ||
{ | ||
cout<<i*4+j<<" "; | ||
} | ||
i++; | ||
} | ||
t=n-4*t; | ||
for(auto j:vec[t-4]) | ||
{ | ||
cout<<i*4+j<<" "; | ||
} | ||
return; | ||
} | ||
|
||
int32_t main() | ||
{ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
int t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
solve(); | ||
cout<<"\n"; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include<bits/stdc++.h> | ||
#define yes cout<<"Yes"<<"\n" | ||
#define no cout<<"No"<<"\n" | ||
#define endl "\n" | ||
#define int long long | ||
using ll=long long; | ||
using namespace std; | ||
|
||
void solve() | ||
{ | ||
int n; | ||
string s; | ||
cin>>n>>s; | ||
int i=0; | ||
while(s[i]=='0') | ||
{ | ||
cout<<0; | ||
i++; | ||
} | ||
if(i<=n-2) | ||
{ | ||
cout<<1; | ||
i++; | ||
while(i<n) | ||
{ | ||
cout<<0; | ||
i++; | ||
} | ||
return; | ||
} | ||
else | ||
{ | ||
cout<<s.substr(i); | ||
} | ||
} | ||
|
||
int32_t main() | ||
{ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
int t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
solve(); | ||
cout<<endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include<bits/stdc++.h> | ||
#define yes cout<<"Yes"<<"\n" | ||
#define no cout<<"No"<<"\n" | ||
#define endl "\n" | ||
#define int long long | ||
using ll=long long; | ||
using namespace std; | ||
|
||
bool solve() | ||
{ | ||
int a,b,c,d; | ||
cin>>a>>b>>c>>d; | ||
return (b+d>a+c)?true:false; | ||
} | ||
|
||
int32_t main() | ||
{ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
int t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
solve()?yes:no; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include<bits/stdc++.h> | ||
#define yes cout<<"Yes"<<"\n" | ||
#define no cout<<"No"<<"\n" | ||
#define enter cout<<"\n" | ||
#define endl "\n" | ||
#define all(a) a.begin(),a.end() | ||
#define pb push_back | ||
#define int long long | ||
using ll=long long; | ||
using ull=unsigned long long; | ||
using namespace std; | ||
|
||
bool sortbycond(const pair<int,int>& a,const pair<int,int>& b) | ||
{ | ||
if(a.first!=b.first) | ||
{ | ||
return (a.first<b.first); | ||
} | ||
else | ||
{ | ||
return (a.second>b.second); | ||
} | ||
} | ||
|
||
int solve() | ||
{ | ||
int n,m,ans=LONG_LONG_MAX,curr; | ||
string s,k; | ||
cin>>n>>m>>s>>k; | ||
for(int i=0;i<=n-m;i++) | ||
{ | ||
curr=0; | ||
for(int j=0;j<m;j++) | ||
{ | ||
curr+=min(abs(s[i+j]-k[j]),10-abs(s[i+j]-k[j])); | ||
} | ||
if(curr==0) | ||
{ | ||
return 0; | ||
} | ||
ans=min(ans,curr); | ||
} | ||
return ans; | ||
} | ||
|
||
int32_t main() | ||
{ | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
int t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
cout<<solve()<<"\n"; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.