From d797c35a6ac4e2abc4da4e85f3da1392c627f98d Mon Sep 17 00:00:00 2001 From: sonavalepratham Date: Tue, 20 Sep 2022 22:56:51 +0530 Subject: [PATCH 1/5] Added CC_KSUB.cpp --- CC_KSUB.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 CC_KSUB.cpp diff --git a/CC_KSUB.cpp b/CC_KSUB.cpp new file mode 100644 index 0000000..13d38bf --- /dev/null +++ b/CC_KSUB.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int t; cin>>t; + while(t--){ + int n, k, g=0, kc=0; cin>>n>>k; + int arr[n]; + for(int i=0; i>arr[i], g=__gcd(g, arr[i]); + int tmpgcd=arr[0]; + for(int i=1; i=k) cout<<"YES\n"; + else cout<<"NO\n"; + } + return 0; +} \ No newline at end of file From aeb52b2c2c9ed3122639fddcb436a61a64de3ae4 Mon Sep 17 00:00:00 2001 From: sonavalepratham Date: Wed, 19 Oct 2022 23:45:26 +0530 Subject: [PATCH 2/5] cses_increasing_array.cpp cses_permutations.cpp --- cses_increasing_array.cpp | 19 +++++++++++++++++++ cses_permutations.cpp | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 cses_increasing_array.cpp create mode 100644 cses_permutations.cpp diff --git a/cses_increasing_array.cpp b/cses_increasing_array.cpp new file mode 100644 index 0000000..74bd330 --- /dev/null +++ b/cses_increasing_array.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +template T mmax(T a, T b){ + return a>b?a:b; +} +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + long long n, sum=0, prev_mx; cin>>n>>prev_mx; + for(int i=0; i>curr; + sum += mmax(prev_mx-curr, (long long int)0); + prev_mx = mmax(curr, prev_mx); + } + cout< +using namespace std; +#define int long long +signed main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int n; cin>>n; + if(n==1){ + cout<<1; return 0; + } + if(n<4){ + cout<<"NO SOLUTION"; + return 0; + } + for(int i=2; i<=n; i+=2) cout< Date: Sun, 6 Nov 2022 22:22:51 +0530 Subject: [PATCH 3/5] cses problems --- cses_NumberSpiral.cpp | 27 +++++++++++++++++++++++++++ cses_TwoKnights.cpp | 13 +++++++++++++ cses_bitstrings.cpp | 19 +++++++++++++++++++ cses_palindromereorder.cpp | 29 +++++++++++++++++++++++++++++ cses_trailingzeros.cpp | 12 ++++++++++++ cses_twosets.cpp | 30 ++++++++++++++++++++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 cses_NumberSpiral.cpp create mode 100644 cses_TwoKnights.cpp create mode 100644 cses_bitstrings.cpp create mode 100644 cses_palindromereorder.cpp create mode 100644 cses_trailingzeros.cpp create mode 100644 cses_twosets.cpp diff --git a/cses_NumberSpiral.cpp b/cses_NumberSpiral.cpp new file mode 100644 index 0000000..087d724 --- /dev/null +++ b/cses_NumberSpiral.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +#define int long long + +signed main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int q; cin>>q; + while(q--){ + int r, c; cin>>r>>c; + if(r==c){ + cout<<(r-1)*(r-1)+r<<"\n"; + continue; + } + int mx=max(r, c)-1; + mx*=mx; + if((max(r, c)&1 and max(r, c)==c) or (max(r, c)%2==0 and max(r, c)==r)){ + cout< +using namespace std; +#define int long long +signed main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int n; cin>>n; + for(int i=1; i<=n; i++){ + cout<<(i*i*(i*i-1))/2-4*(i-1)*(i-2)<<"\n"; + } + return 0; +} \ No newline at end of file diff --git a/cses_bitstrings.cpp b/cses_bitstrings.cpp new file mode 100644 index 0000000..355f2aa --- /dev/null +++ b/cses_bitstrings.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; +#define P 1000000007 +int pow(int a, int n){ + if(n==0) return 1; + if(n==1) return a; + long long tmp = pow(a, n/2)%P; + if(n&1) return (((tmp*tmp)%P)*a)%P; + return (tmp*tmp)%P; +} + +signed main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int n; cin>>n; + cout< +using namespace std; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + string s; cin>>s; + unordered_map mp; + for(auto it : s) mp[it]++; + int oc=0, cnt=0; + char c; + for(auto it : mp) if(it.second &1) oc++, c=it.first, cnt=it.second; + if(oc>1 or (s.size()%2==1 and oc!=1)) cout<<"NO SOLUTION"; + else{ + deque q; + while(cnt-->0) q.push_front(c); + mp[c]=0; + for(auto it : mp){ + while(mp[it.first]){ + q.push_back(it.first); + q.push_front(it.first); + mp[it.first]-=2; + } + } + while(q.size()){ cout< +using namespace std; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + long long n, ans=0; cin>>n; + for(long long i=5; n/i>0; i*=5) ans+=n/i; + cout< +using namespace std; +#define int long long +signed main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int n; cin>>n; + if(((n*(n+1))/2) &1) + { + cout<<"NO"; + return 0; + } + cout<<"YES\n"; + int ans=(n*(n+1))/4; + vector s1, s2; + for(int i=n; i>0; i--){ + if(i<=ans){ + s1.push_back(i); + ans-=i; + } + else s2.push_back(i); + } + cout< Date: Sun, 6 Nov 2022 23:15:35 +0530 Subject: [PATCH 4/5] greycode problem --- cses_graycode.cpp | 24 ++++++++++++++++++++++++ leetcode_greycode.cpp | 11 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 cses_graycode.cpp create mode 100644 leetcode_greycode.cpp diff --git a/cses_graycode.cpp b/cses_graycode.cpp new file mode 100644 index 0000000..d2eae1a --- /dev/null +++ b/cses_graycode.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +vector fun(int n){ + if(n<1) return {}; + if(n==1) return {"0", "1"}; + vector res=fun(n-1), res2=res; + for(int i=0; i=0; i--) res.push_back(res2[i]); + return res; +} + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int n; cin>>n; + vector res = fun(n); + for(auto it : res){ + cout << it <<"\n"; + } + return 0; +} \ No newline at end of file diff --git a/leetcode_greycode.cpp b/leetcode_greycode.cpp new file mode 100644 index 0000000..c56be15 --- /dev/null +++ b/leetcode_greycode.cpp @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int n; cin>>n; + for(int i=0; i<(1<>1)) <<" "; + return 0; +} \ No newline at end of file From 29dab40be570273496a2dab9d4cb75a47cb257d9 Mon Sep 17 00:00:00 2001 From: sonavalepratham Date: Sat, 11 Feb 2023 00:07:27 +0530 Subject: [PATCH 5/5] appledivision chessboardandqueens permutations greycode --- appledivision.cpp | 29 ++++++++++++++++++ cses_chessboardandqueens.cpp | 58 ++++++++++++++++++++++++++++++++++++ cses_permutations.cpp | 6 ++-- leetcode_greycode.cpp | 4 +-- 4 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 appledivision.cpp create mode 100644 cses_chessboardandqueens.cpp diff --git a/appledivision.cpp b/appledivision.cpp new file mode 100644 index 0000000..cd36ce3 --- /dev/null +++ b/appledivision.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +#define int long long + +int res = INT_MAX, sum=0; +int cnt=0; +void fun(vector&arr, int i, int s) +{ + res=min(abs(sum-2*s), res); + if(i<0) + return; + fun(arr, i-1, s); + fun(arr, i-1, s+arr[i]); +} + +signed main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int n; cin>>n; + vector arr(n); + + for(int i=0; i>arr[i], sum+=arr[i]; + + fun(arr, n-1, 0); + + cout< +using namespace std; + +#define int long long + +bool canplace(int r, int c, vector> &arr){ + + if(arr[r][c]!='.') return false; + + for(int i=r; i>=0; i--) + if(arr[i][c]=='P') return false; + + for(int i=c; i>=0; i--) + if(arr[r][i]=='P') return false; + + for(int i=r, j=c; i>=0 && j>=0; i--, j--) + if(arr[i][j]=='P') return false; + + for(int i=r, j=c; i>=0 && j<8; i--, j++) + if(arr[i][j]=='P') return false; + //cout<> &grid, int r, int c, int&res, int cnt) +{ + if(cnt==8) res++; + if(cnt>8 or r>7 or c>7) return; + for(int i=r; i<8; i++){ + for(int j=c; j<8; j++){ + cout<> grid(8,vector(8)); + for(int i=0; i<8; i++) + for(int j=0; j<8; j++) + cin>>grid[i][j]; + + + int res=0; + fun(grid, 0, 0, res, 0); + cout<>n; - for(int i=0; i<(1<>1)) <<" "; - return 0; + for(int i=0; i<(1<>1)) <<" "; + return 0; } \ No newline at end of file