diff --git a/Codeforces_Problem_Solving/L_Problems/L. Controllers/.cph/.1.cpp_306695f268e1dd92edcdf260b06ed238.prob b/Codeforces_Problem_Solving/L_Problems/L. Controllers/.cph/.1.cpp_306695f268e1dd92edcdf260b06ed238.prob new file mode 100644 index 0000000..7d8c396 --- /dev/null +++ b/Codeforces_Problem_Solving/L_Problems/L. Controllers/.cph/.1.cpp_306695f268e1dd92edcdf260b06ed238.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\L_Problems\\L. Controllers\\1.cpp","tests":[{"id":1679763541529,"input":"8\n+-+---+-\n5\n2 1\n10 3\n7 9\n10 10\n5 3","output":"YES\nNO\nNO\nNO\nYES"},{"id":1679763556958,"input":"6\n+-++--\n2\n9 7\n1 1","output":"YES\nYES"},{"id":1679764171400,"input":"20\n+-----+--+--------+-\n2\n1000000000 99999997\n250000000 1000000000","output":"NO\nYES"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\L_Problems\\L. Controllers\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/L_Problems/L. Controllers/1.bin b/Codeforces_Problem_Solving/L_Problems/L. Controllers/1.bin new file mode 100644 index 0000000..4599647 Binary files /dev/null and b/Codeforces_Problem_Solving/L_Problems/L. Controllers/1.bin differ diff --git a/Codeforces_Problem_Solving/L_Problems/L. Controllers/1.cpp b/Codeforces_Problem_Solving/L_Problems/L. Controllers/1.cpp new file mode 100644 index 0000000..e7e4521 --- /dev/null +++ b/Codeforces_Problem_Solving/L_Problems/L. Controllers/1.cpp @@ -0,0 +1,202 @@ +#include + +#include +#include +using namespace __gnu_pbds; + +using namespace std; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; + +int gcd(int a, int b) {if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a/gcd(a,b)*b);} +int power(int a, int b) {int res=1; while(b > 0) {if(b & 1) res= (res*a); a=(a*a); b=b >> 1;} return res;} +int inv_mult(int i) {if (i == 1) return 1; return (mod97 - ((mod97 / i) * inv_mult(mod97 % i)) % mod97) % mod97;} +string decToBinary(int n){string s=""; int i=0; while(n > 0) {s=to_string(n % 2) + s; n=n/2; i++;}return s;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool isPerfectSquare(int x) {if (x>=0) {int sr = sqrt(x);return (sr * sr == x);}return false;} +int modpower(int x, int y){int res=1; x=x % mod97; while(y>0){if(y&1) res = (res*x) % mod97; y=y>>1; x=(x*x) % mod97;}return res;} +int modInverse(int n){return power(n, modg - 2);} +int ncr(int n,int r, int p){if(r > n){return 0;}if(n < 0 || r < 0){return 0;}if (r==0) return 1;int fac[n+1]; fac[0] = 1; for (int i=1 ; i<=n; i++) fac[i] = fac[i-1]*i%p;return (fac[n]* power(fac[r], p-2)%p*power(fac[n-r], p-2) % p) % p;} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +vector > adj ; +vector visited ; +vector value ; + +bool solve(){ + //adj.assign(n + 1 , vector()); + //visited.assign(n + 1 , false) ; + //value.assign(n + 1 , 0) ; + int n ; + cin >> n ; + string s ; + cin >> s ; + int positive = 0 ; + int negative = 0 ; + for(int i = 0 ; i < n ; ++i){ + if(s[i] == '+') positive ++ ; + else negative ++ ; + } + int q ; + cin >> q ; + for(int i = 0 ; i < q ; ++i){ + int x , y ; + cin >> x >> y ; + if(positive == negative) yes + else if(positive > negative) { + if(x > y) { + int has_to_be_greater = negative * x ; + int lesser = positive * y ; + if(has_to_be_greater == lesser) { + yes + } + else if(has_to_be_greater < lesser){ + no + } + else{ + int t = has_to_be_greater - lesser ; + if((x + y) % t == 0){ + yes + }else{ + no + } + } + }else{ + int has_to_be_greater = negative * y ; + int lesser = positive * x ; + if(has_to_be_greater == lesser) { + yes + } + else if(has_to_be_greater < lesser){ + no + } + else{ + int t = has_to_be_greater - lesser ; + if((x + y) % t == 0){ + yes + }else{ + no + } + } + } + }else{ + if(x > y) { + int has_to_be_greater = positive * x ; + int lesser = negative * y ; + if(has_to_be_greater == lesser) { + yes + } + else if(has_to_be_greater < lesser){ + no + } + else{ + int t = has_to_be_greater - lesser ; + if((x + y) % t == 0){ + yes + }else{ + no + } + } + }else{ + int has_to_be_greater = positive * y ; + int lesser = negative * x ; + if(has_to_be_greater == lesser) { + yes + } + else if(has_to_be_greater < lesser){ + no + } + else{ + int t = has_to_be_greater - lesser ; + if((x + y) % t == 0){ + yes + }else{ + no + } + } + } + } + } + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stder); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/L_Problems/L. Summation/.cph/.1.cpp_48f3b75b5686e739bc3e72c38b41f676.prob b/Codeforces_Problem_Solving/L_Problems/L. Summation/.cph/.1.cpp_48f3b75b5686e739bc3e72c38b41f676.prob new file mode 100644 index 0000000..c2a3fa9 --- /dev/null +++ b/Codeforces_Problem_Solving/L_Problems/L. Summation/.cph/.1.cpp_48f3b75b5686e739bc3e72c38b41f676.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\L_Problems\\L. Summation\\1.cpp","tests":[{"id":1686514812427,"input":"4\n1 4 2 7\n","output":""},{"id":1686514833132,"input":"4\n5 5 5 5","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\L_Problems\\L. Summation\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/L_Problems/L. Summation/1.bin b/Codeforces_Problem_Solving/L_Problems/L. Summation/1.bin new file mode 100644 index 0000000..4e3ebaa Binary files /dev/null and b/Codeforces_Problem_Solving/L_Problems/L. Summation/1.bin differ diff --git a/Codeforces_Problem_Solving/L_Problems/L. Summation/1.cpp b/Codeforces_Problem_Solving/L_Problems/L. Summation/1.cpp new file mode 100644 index 0000000..5900fc1 --- /dev/null +++ b/Codeforces_Problem_Solving/L_Problems/L. Summation/1.cpp @@ -0,0 +1,116 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; +template using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + int sum = 0 ; + function f = [&](int i) -> void { + if(i == n) return ; + f(i + 1) ; + sum += v[i] ; + }; + f(0) ; + cout << sum << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/M_Problems/M. Suffix Sum/.cph/.1.cpp_024aeebff1cc7492bde85f24155ada66.prob b/Codeforces_Problem_Solving/M_Problems/M. Suffix Sum/.cph/.1.cpp_024aeebff1cc7492bde85f24155ada66.prob new file mode 100644 index 0000000..13fadc0 --- /dev/null +++ b/Codeforces_Problem_Solving/M_Problems/M. Suffix Sum/.cph/.1.cpp_024aeebff1cc7492bde85f24155ada66.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\M_Problems\\M. Suffix Sum\\1.cpp","tests":[{"id":1686664797328,"input":"5 3\n1 8 2 10 3\n","output":"15\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\M_Problems\\M. Suffix Sum\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/M_Problems/M. Suffix Sum/1.bin b/Codeforces_Problem_Solving/M_Problems/M. Suffix Sum/1.bin new file mode 100644 index 0000000..ecfe38c Binary files /dev/null and b/Codeforces_Problem_Solving/M_Problems/M. Suffix Sum/1.bin differ diff --git a/Codeforces_Problem_Solving/M_Problems/M. Suffix Sum/1.cpp b/Codeforces_Problem_Solving/M_Problems/M. Suffix Sum/1.cpp new file mode 100644 index 0000000..77c3cbd --- /dev/null +++ b/Codeforces_Problem_Solving/M_Problems/M. Suffix Sum/1.cpp @@ -0,0 +1,116 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; +template using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n , m ; + cin >> n >> m ; + iv(v , n) + int sum = 0 ; + function f = [&](int n, int i) -> void { + if(i == n) return ; + if(i >= n - m) sum += v[i] ; + f(n , i + 1) ; + }; + f(n , 0) ; + cout << sum << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/N_Problems/N. Number Reduction/.cph/.1.cpp_09c58019fd4833ceddaece633e652178.prob b/Codeforces_Problem_Solving/N_Problems/N. Number Reduction/.cph/.1.cpp_09c58019fd4833ceddaece633e652178.prob new file mode 100644 index 0000000..eed2fc4 --- /dev/null +++ b/Codeforces_Problem_Solving/N_Problems/N. Number Reduction/.cph/.1.cpp_09c58019fd4833ceddaece633e652178.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\N_Problems\\N. Number Reduction\\1.cpp","tests":[{"id":1704966110043,"input":"5\n10000\n4\n1337\n0\n987654321\n6\n66837494128\n5\n7808652\n3","output":"1\n1337\n321\n344128\n7052"},{"id":1704966492682,"input":"1\n123450\n4","output":"10"},{"id":1704966910792,"input":"5\n123\n2\n312\n1\n312\n2\n321\n2\n213\n2","output":"1\n12\n1\n1\n1"},{"id":1704967256520,"input":"4\n12\n0\n21\n0\n113124\n2\n21\n1","output":"12\n21\n1112\n1"},{"id":1704967766610,"input":"1\n201\n2","output":"1"},{"id":1704969668167,"input":"1\n2001\n3","output":"1"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\N_Problems\\N. Number Reduction\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/N_Problems/N. Number Reduction/1.bin b/Codeforces_Problem_Solving/N_Problems/N. Number Reduction/1.bin new file mode 100644 index 0000000..67f9d3d Binary files /dev/null and b/Codeforces_Problem_Solving/N_Problems/N. Number Reduction/1.bin differ diff --git a/Codeforces_Problem_Solving/N_Problems/N. Number Reduction/1.cpp b/Codeforces_Problem_Solving/N_Problems/N. Number Reduction/1.cpp new file mode 100644 index 0000000..11ced18 --- /dev/null +++ b/Codeforces_Problem_Solving/N_Problems/N. Number Reduction/1.cpp @@ -0,0 +1,186 @@ +#include +using namespace std; +#pragma GCC optimize("O3") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +// Policy based data structures(PBDS) C++ STL +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// order_of_key(k): returns count of elements strictly smaller than k +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pairs only define simply by ordered_set s +typedef tree, null_type, less_equal>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; +templateusing Tree = tree, rb_tree_tag, tree_order_statistics_node_update> ; // here T can be anything like pair,vector,map,pair_of_pair // USE it like Tree > s; for pairs + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long // typedef array p ; pair h ye +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< 0) {if(y & 1) res = (res * (long long)x) ; x = ((long long)x * (long long)x) ; y = y >> 1 ;} return res ;} +int modpower(int x, int y){long long res = 1; x = x % MOD; while(y > 0){if(y&1) res = (res * (long long)x) % MOD; y = y >> 1; x = ((long long)x * (long long)x) % MOD ;}return res ;} +int modinv(int x){return modpower(x , MOD - 2) ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +vector giveme_it_isprime_or_not(int n){vector isPrime(n+1, 1);isPrime[0]=isPrime[1]=false;for(int i = 2; i * i <= n; ++i){if(isPrime[i] == true){for(int j = 2 * i; j <= n; j += i){isPrime[j] = false;}}} return isPrime;} // Time Complexity - O(n * sqrt(n) * log(n)) +vector givemeprimes(int n) {int*arr = new int[n + 1](); vector vect; for(int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for(int j = i * i; j <= n; j += i)arr[j] = 1;} return vect;} // can be calculated in O(n) +vector> givemedivisors(int n){int*arr = new int[n + 1]();vector > vect(n + 1);for(int i = 2; i <= n; ++i){if(arr[i] == 0){for(int j = i; j <= n; j += i){vect[j].pb(i);arr[i] = 1;}}} return vect ;} +vector givemesmallestprimefactors(int n){vector SPF(n + 1);for(int i = 0; i <= n; ++i){SPF[i] = i;}for(int i = 2; i <= n; ++i){if(SPF[i] == i){for(int j = i; j <= n; j += i){if(SPF[j] == j){SPF[j] = i;}}}}return SPF ;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid(l, r)(rng);} + +bool solve(){ + string s ; + cin >> s ; + // cout << s << nl ; // correct + int x ; + cin >> x ; + int n = s.size() ; + + + int p = 0; + for (int i = 0; i <= x; i++) { + if (s[i] != '0' && s[i] < s[p]) { + p = i; + } + } + + x -= p; + + string ans; + ans += s[p]; + for (int i = p + 1; i < n; i++) { + while (x > 0 && ans.size() > 1 && s[i] < ans.back()) { + ans.pop_back(); + x--; + } + ans += s[i]; + } + while (x--) { + ans.pop_back(); + } + cout << ans << "\n"; + + + // stack st ; + // // cout << n << nl ; // correct + // int k = 0 ; + // for(int i = 0 ; i < n ; ++i){ + // int t = s[i] - '0' ; + // while(!st.empty() and st.top() > t and k < x){ + // if(t == 0 and st.size() == 1) break ; + // st.pop() ; + // k += 1 ; + // } + // while(!st.empty() and st.top() == 0 and k < x - 1){ + // if(st.size() > 1){ + // int sees = st.top() ; st.pop() ; + // if(t < st.top() and t != 0){ + // st.pop() ; + // k += 2 ; + // } + // else{ + // st.push(sees) ; + // break ; + // } + // } + // else{ + // break ; + // } + // } + // // cout << st.size() << nl ; + // st.push(t) ; + // } + // string ans = "" ; + // while(!st.empty() and k < x){ + // st.pop() ; + // k += 1 ; + // } + // while(!st.empty()){ + // ans += (st.top() + '0') ; + // st.pop() ; + // } + // reverse(all(ans)) ; + // cout << ans << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t ; + cin >> t ; + //int count = 1 ; + + int tt = 0 ; + while (t--){ + //cout << "Case #" << count << ": "; + // tt += 1 ; + // if(tt==495){ + // string s;cin>>s;int x;cin>>x;cout< +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int r , c ; + cin >> r >> c ; + vector > first(r + 1 , vector(c + 1 , 0)) ; + vector > second(r + 1 , vector(c + 1 , 0)) ; + for(int i = 0 ; i < r ; ++i){ + for(int j = 0 ; j < c ; ++j){ + cin >> first[i][j] ; + } + } + for(int i = 0 ; i < r ; ++i){ + for(int j = 0 ; j < c ; ++j){ + cin >> second[i][j] ; + } + } + function f = [&](int i, int j) -> void { + if(i == r) return ; + for(int ii = 0 ; ii < c ; ++ii){ + cout << first[i][ii] + second[i][ii] ; + if(ii == c - 1) cout << nl ; + else cout << " " ; + } + f(i + 1 , 0) ; + }; + f(0 , 0) ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/O_Problems/O. Fibonacci/.cph/.1.cpp_07d3ed3e1e60bb7a8ecd71e46b94f7c3.prob b/Codeforces_Problem_Solving/O_Problems/O. Fibonacci/.cph/.1.cpp_07d3ed3e1e60bb7a8ecd71e46b94f7c3.prob new file mode 100644 index 0000000..1a65a21 --- /dev/null +++ b/Codeforces_Problem_Solving/O_Problems/O. Fibonacci/.cph/.1.cpp_07d3ed3e1e60bb7a8ecd71e46b94f7c3.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\O_Problems\\O. Fibonacci\\1.cpp","tests":[{"id":1686665058649,"input":"5","output":""},{"id":1686665062958,"input":"30","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\O_Problems\\O. Fibonacci\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/O_Problems/O. Fibonacci/1.bin b/Codeforces_Problem_Solving/O_Problems/O. Fibonacci/1.bin new file mode 100644 index 0000000..ccc0e0a Binary files /dev/null and b/Codeforces_Problem_Solving/O_Problems/O. Fibonacci/1.bin differ diff --git a/Codeforces_Problem_Solving/O_Problems/O. Fibonacci/1.cpp b/Codeforces_Problem_Solving/O_Problems/O. Fibonacci/1.cpp new file mode 100644 index 0000000..12d8fef --- /dev/null +++ b/Codeforces_Problem_Solving/O_Problems/O. Fibonacci/1.cpp @@ -0,0 +1,118 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; +template using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + vector arr(32) ; + arr[0] = 0 ; + arr[1] = 1 ; + // cout << arr[0] << nl ; + function f = [&](int n, int i) -> void { + if(i == 31) return ; + arr[i] = (arr[i - 1] + arr[i - 2]) ; + f(n , i + 1) ; + }; + f(n , 2) ; + cout << arr[n - 1] << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/P_Problems/P. Log2/.cph/.1.cpp_3dc104b0fd11943f9d3df69111361144.prob b/Codeforces_Problem_Solving/P_Problems/P. Log2/.cph/.1.cpp_3dc104b0fd11943f9d3df69111361144.prob new file mode 100644 index 0000000..6e97851 --- /dev/null +++ b/Codeforces_Problem_Solving/P_Problems/P. Log2/.cph/.1.cpp_3dc104b0fd11943f9d3df69111361144.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\P_Problems\\P. Log2\\1.cpp","tests":[{"id":1686764057610,"input":"1","output":""},{"id":1686764060177,"input":"5","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\P_Problems\\P. Log2\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/P_Problems/P. Log2/1.bin b/Codeforces_Problem_Solving/P_Problems/P. Log2/1.bin new file mode 100644 index 0000000..7b300b2 Binary files /dev/null and b/Codeforces_Problem_Solving/P_Problems/P. Log2/1.bin differ diff --git a/Codeforces_Problem_Solving/P_Problems/P. Log2/1.cpp b/Codeforces_Problem_Solving/P_Problems/P. Log2/1.cpp new file mode 100644 index 0000000..6797e11 --- /dev/null +++ b/Codeforces_Problem_Solving/P_Problems/P. Log2/1.cpp @@ -0,0 +1,115 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; +template using ordered_map = tree, rb_tree_tag, tree_order_statistics_node_update>; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + int i = 0 ; + function f = [&](int n) -> void { + if(n == 0) return ; + i += 1 ; + f(n / 2) ; + }; + f(n) ; + cout << i - 1 << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/Q_Problems/Q. 3n + 1 sequence/.cph/.1.cpp_aff6f57cf3f87324f0ef2f22613426bd.prob b/Codeforces_Problem_Solving/Q_Problems/Q. 3n + 1 sequence/.cph/.1.cpp_aff6f57cf3f87324f0ef2f22613426bd.prob new file mode 100644 index 0000000..488f17e --- /dev/null +++ b/Codeforces_Problem_Solving/Q_Problems/Q. 3n + 1 sequence/.cph/.1.cpp_aff6f57cf3f87324f0ef2f22613426bd.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\Q_Problems\\Q. 3n + 1 sequence\\1.cpp","tests":[{"id":1687013094761,"input":"1","output":""},{"id":1687013099623,"input":"2","output":""},{"id":1687013102119,"input":"3","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\Q_Problems\\Q. 3n + 1 sequence\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/Q_Problems/Q. 3n + 1 sequence/1.bin b/Codeforces_Problem_Solving/Q_Problems/Q. 3n + 1 sequence/1.bin new file mode 100644 index 0000000..44251db Binary files /dev/null and b/Codeforces_Problem_Solving/Q_Problems/Q. 3n + 1 sequence/1.bin differ diff --git a/Codeforces_Problem_Solving/Q_Problems/Q. 3n + 1 sequence/1.cpp b/Codeforces_Problem_Solving/Q_Problems/Q. 3n + 1 sequence/1.cpp new file mode 100644 index 0000000..039c860 --- /dev/null +++ b/Codeforces_Problem_Solving/Q_Problems/Q. 3n + 1 sequence/1.cpp @@ -0,0 +1,116 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + int j = n ; + int cnt = 0 ; + function f = [&](int n, int j) -> void { + if(j == 1) return ; + cnt += 1 ; + if(j % 2 == 1) f(n , 3 * j + 1) ; + else f(n , j / 2) ; + }; + f(n , j) ; + cout << cnt + 1 << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/R_Problems/R. Palindrome Array/.cph/.1.cpp_a929bbc04173b39247e54da0ed9406d6.prob b/Codeforces_Problem_Solving/R_Problems/R. Palindrome Array/.cph/.1.cpp_a929bbc04173b39247e54da0ed9406d6.prob new file mode 100644 index 0000000..85c8a1c --- /dev/null +++ b/Codeforces_Problem_Solving/R_Problems/R. Palindrome Array/.cph/.1.cpp_a929bbc04173b39247e54da0ed9406d6.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\R_Problems\\R. Palindrome Array\\1.cpp","tests":[{"id":1687013295257,"input":"5\n1 3 2 3 1\n","output":""},{"id":1687013301497,"input":"4\n1 2 2 1\n","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\R_Problems\\R. Palindrome Array\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/R_Problems/R. Palindrome Array/1.bin b/Codeforces_Problem_Solving/R_Problems/R. Palindrome Array/1.bin new file mode 100644 index 0000000..1f555de Binary files /dev/null and b/Codeforces_Problem_Solving/R_Problems/R. Palindrome Array/1.bin differ diff --git a/Codeforces_Problem_Solving/R_Problems/R. Palindrome Array/1.cpp b/Codeforces_Problem_Solving/R_Problems/R. Palindrome Array/1.cpp new file mode 100644 index 0000000..6da1c99 --- /dev/null +++ b/Codeforces_Problem_Solving/R_Problems/R. Palindrome Array/1.cpp @@ -0,0 +1,118 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + int i = 0 ; + int j = n - 1 ; + int ff = 0 ; + function f = [&](int i, int j) -> void { + if(i >= j) return ; + if(v[i] != v[j]) ff = 1 ; + f(i + 1 , j - 1) ; + }; + f(i , j) ; + if(!ff) yes + else no + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/S_Problems/S. Array Average/.cph/.1.cpp_427840987a9fc8939d610f00cd6c4d47.prob b/Codeforces_Problem_Solving/S_Problems/S. Array Average/.cph/.1.cpp_427840987a9fc8939d610f00cd6c4d47.prob new file mode 100644 index 0000000..6ce9cee --- /dev/null +++ b/Codeforces_Problem_Solving/S_Problems/S. Array Average/.cph/.1.cpp_427840987a9fc8939d610f00cd6c4d47.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\S_Problems\\S. Array Average\\1.cpp","tests":[{"id":1687016931666,"input":"5\n1 2 3 4 5\n","output":"3.000000\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\S_Problems\\S. Array Average\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/S_Problems/S. Array Average/1.bin b/Codeforces_Problem_Solving/S_Problems/S. Array Average/1.bin new file mode 100644 index 0000000..8f8b3f3 Binary files /dev/null and b/Codeforces_Problem_Solving/S_Problems/S. Array Average/1.bin differ diff --git a/Codeforces_Problem_Solving/S_Problems/S. Array Average/1.cpp b/Codeforces_Problem_Solving/S_Problems/S. Array Average/1.cpp new file mode 100644 index 0000000..5a8dcbe --- /dev/null +++ b/Codeforces_Problem_Solving/S_Problems/S. Array Average/1.cpp @@ -0,0 +1,118 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + ld n ; + cin >> n ; + iv(v , n) + ld sum = 0 ; + function f = [&](int i, int n) -> void { + if(i == -1) return ; + sum += v[i] ; + f(i - 1 , n) ; + }; + f(n - 1 , n) ; + // cout << sum << nl ; + ld ok = sum / n ; + cout << setprecision(6) << fixed ; + cout << ok << nl ; + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/T_Problems/T. Combination/.cph/.1.cpp_e4ed328748dbd28906dd981091f27fc7.prob b/Codeforces_Problem_Solving/T_Problems/T. Combination/.cph/.1.cpp_e4ed328748dbd28906dd981091f27fc7.prob new file mode 100644 index 0000000..3b86b3d --- /dev/null +++ b/Codeforces_Problem_Solving/T_Problems/T. Combination/.cph/.1.cpp_e4ed328748dbd28906dd981091f27fc7.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\T_Problems\\T. Combination\\1.cpp","tests":[{"id":1687444065643,"input":"4 2\n","output":""},{"id":1687444067686,"input":"3 3","output":""},{"id":1687444343070,"input":"30 15","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\T_Problems\\T. Combination\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/T_Problems/T. Combination/1.bin b/Codeforces_Problem_Solving/T_Problems/T. Combination/1.bin new file mode 100644 index 0000000..405bfdb Binary files /dev/null and b/Codeforces_Problem_Solving/T_Problems/T. Combination/1.bin differ diff --git a/Codeforces_Problem_Solving/T_Problems/T. Combination/1.cpp b/Codeforces_Problem_Solving/T_Problems/T. Combination/1.cpp new file mode 100644 index 0000000..4fae5b0 --- /dev/null +++ b/Codeforces_Problem_Solving/T_Problems/T. Combination/1.cpp @@ -0,0 +1,135 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + + int n , r ; + int dp[30 + 1][30 + 1] ; +bool solve(){ + cin >> n >> r ; + int ans = 1 ; + int ans2 = 1 ; + int c1 = 0 ; + int c2 = 0 ; + if(n < r){ + cout << 0 << nl ; + return true ; + } + function f = [&](int i, int j) -> int { + // if(i == n + 1) return ; + // if(j >= r + 1) {c1 = 1 ;} + // else {c1 = j ;} + // if(k >= (n - r) + 1) {c2 = 1 ;} + // else {c2 = k ;} + // ans *= i ; + // ans2 *= c1 ; + // ans2 *= c2 ; + // // cout << ans << " " ; + // f(i + 1 , j + 1 , k + 1) ; + if(j == 0 || j == i){ + return 1 ; + } + if(dp[i][j] != 0) return dp[i][j] ; + return dp[i][j] = f(i - 1 , j - 1) + f(i - 1 , j) ; + }; + cout << f(n , r) << nl ; + // cout << ans << + // cout << ans / ans2 << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/U_Problems/U. Knapsack/.cph/.1.cpp_88b98f63298bd75c6c2b313b91598f13.prob b/Codeforces_Problem_Solving/U_Problems/U. Knapsack/.cph/.1.cpp_88b98f63298bd75c6c2b313b91598f13.prob new file mode 100644 index 0000000..77879ca --- /dev/null +++ b/Codeforces_Problem_Solving/U_Problems/U. Knapsack/.cph/.1.cpp_88b98f63298bd75c6c2b313b91598f13.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\U_Problems\\U. Knapsack\\1.cpp","tests":[{"id":1687680331201,"input":"3 8\n3 30\n4 50\n5 60\n","output":"90"},{"id":1687680340926,"input":"6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2\n","output":"17"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\U_Problems\\U. Knapsack\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/U_Problems/U. Knapsack/1.bin b/Codeforces_Problem_Solving/U_Problems/U. Knapsack/1.bin new file mode 100644 index 0000000..c5c852a Binary files /dev/null and b/Codeforces_Problem_Solving/U_Problems/U. Knapsack/1.bin differ diff --git a/Codeforces_Problem_Solving/U_Problems/U. Knapsack/1.cpp b/Codeforces_Problem_Solving/U_Problems/U. Knapsack/1.cpp new file mode 100644 index 0000000..b164e78 --- /dev/null +++ b/Codeforces_Problem_Solving/U_Problems/U. Knapsack/1.cpp @@ -0,0 +1,124 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n , w ; + cin >> n >> w ; + vector weight(n) ; + vector value(n) ; + for(int i = 0 ; i < n ; ++i){ + cin >> weight[i] >> value[i] ; + } + vector > dp(n + 1 , vector (w + 1 , -1)) ; + function rec = [&](int W, int i) -> int { + if(W <= 0 || i == n) return 0 ; + if(dp[i][W] != -1) return dp[i][W] ; + int ans = INT_MIN ; + if(weight[i] <= W){ + ans = max(rec(W - weight[i] , i + 1) + value[i] , rec(W , i + 1)) ; + }else{ + ans = rec(W , i + 1) ; + } + return dp[i][W] = ans ; + }; + cout << rec(w , 0) << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/V_Problems/V. Creating Expression1/.cph/.1.cpp_1c1d4d6b9a8fea6780a72d030d1a3e59.prob b/Codeforces_Problem_Solving/V_Problems/V. Creating Expression1/.cph/.1.cpp_1c1d4d6b9a8fea6780a72d030d1a3e59.prob new file mode 100644 index 0000000..3c57d43 --- /dev/null +++ b/Codeforces_Problem_Solving/V_Problems/V. Creating Expression1/.cph/.1.cpp_1c1d4d6b9a8fea6780a72d030d1a3e59.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\V_Problems\\V. Creating Expression1\\1.cpp","tests":[{"id":1687682244937,"input":"5 5\n1 2 3 4 5\n","output":"YES"},{"id":1687682288130,"input":"5 2\n1 2 3 4 5","output":"NO"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\V_Problems\\V. Creating Expression1\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/V_Problems/V. Creating Expression1/1.bin b/Codeforces_Problem_Solving/V_Problems/V. Creating Expression1/1.bin new file mode 100644 index 0000000..97e19d8 Binary files /dev/null and b/Codeforces_Problem_Solving/V_Problems/V. Creating Expression1/1.bin differ diff --git a/Codeforces_Problem_Solving/V_Problems/V. Creating Expression1/1.cpp b/Codeforces_Problem_Solving/V_Problems/V. Creating Expression1/1.cpp new file mode 100644 index 0000000..4714235 --- /dev/null +++ b/Codeforces_Problem_Solving/V_Problems/V. Creating Expression1/1.cpp @@ -0,0 +1,117 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n , x ; + cin >> n >> x ; + iv(v , n) + int f = 0 ; + vector > dp(n + 1 , vector (2 , -1)) ; + function func = [&](int i, int sum) -> void { + if(i == n - 1) { + if(sum == x){ + f = 1 ; + } + return ; + } + func(i + 1 , sum - v[i + 1]) ; + func(i + 1 , sum + v[i + 1]) ; + }; + func(0 , v[0]) ; + if(f) yes + else no + return true ; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/W_Problems/W. Reach Value/.cph/.1.cpp_07f9e05a7a8b66698ecaf2b0f480474c.prob b/Codeforces_Problem_Solving/W_Problems/W. Reach Value/.cph/.1.cpp_07f9e05a7a8b66698ecaf2b0f480474c.prob new file mode 100644 index 0000000..e4e4029 --- /dev/null +++ b/Codeforces_Problem_Solving/W_Problems/W. Reach Value/.cph/.1.cpp_07f9e05a7a8b66698ecaf2b0f480474c.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\W_Problems\\W. Reach Value\\1.cpp","tests":[{"id":1687801435898,"input":"5\n1\n2\n10\n25\n200\n","output":"YES\nNO\nYES\nNO\nYES\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\W_Problems\\W. Reach Value\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/W_Problems/W. Reach Value/1.bin b/Codeforces_Problem_Solving/W_Problems/W. Reach Value/1.bin new file mode 100644 index 0000000..8ea55a2 Binary files /dev/null and b/Codeforces_Problem_Solving/W_Problems/W. Reach Value/1.bin differ diff --git a/Codeforces_Problem_Solving/W_Problems/W. Reach Value/1.cpp b/Codeforces_Problem_Solving/W_Problems/W. Reach Value/1.cpp new file mode 100644 index 0000000..bb31ba6 --- /dev/null +++ b/Codeforces_Problem_Solving/W_Problems/W. Reach Value/1.cpp @@ -0,0 +1,121 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + int flag = 0 ; + function f = [&](int num) -> void { + if(num > n){ + return ; + } + if(num == n){ + flag = 1 ; + return ; + } + f(num * 10) ; + f(num * 20) ; + }; + f(1) ; + if(flag) yes + else no + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t; + cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + +// Think twice, code once. // rab ne bana di jodi \ No newline at end of file diff --git a/Codeforces_Problem_Solving/X_Problems/X. The maximum path-sum/.cph/.1.cpp_328fa19aa10587a6cd56f65b765930a6.prob b/Codeforces_Problem_Solving/X_Problems/X. The maximum path-sum/.cph/.1.cpp_328fa19aa10587a6cd56f65b765930a6.prob new file mode 100644 index 0000000..eed13ea --- /dev/null +++ b/Codeforces_Problem_Solving/X_Problems/X. The maximum path-sum/.cph/.1.cpp_328fa19aa10587a6cd56f65b765930a6.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\X_Problems\\X. The maximum path-sum\\1.cpp","tests":[{"id":1687801869740,"input":"3 3\n5 2 4\n1 3 5\n9 2 7\n","output":"24"},{"id":1687802396307,"input":"1 1\n-1","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\X_Problems\\X. The maximum path-sum\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/X_Problems/X. The maximum path-sum/1.bin b/Codeforces_Problem_Solving/X_Problems/X. The maximum path-sum/1.bin new file mode 100644 index 0000000..f075b11 Binary files /dev/null and b/Codeforces_Problem_Solving/X_Problems/X. The maximum path-sum/1.bin differ diff --git a/Codeforces_Problem_Solving/X_Problems/X. The maximum path-sum/1.cpp b/Codeforces_Problem_Solving/X_Problems/X. The maximum path-sum/1.cpp new file mode 100644 index 0000000..085648f --- /dev/null +++ b/Codeforces_Problem_Solving/X_Problems/X. The maximum path-sum/1.cpp @@ -0,0 +1,121 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n , m ; + cin >> n >> m ; + vector > mat(n + 1 , vector (m + 1)) , dp(n + 1 , vector (m + 1 , -1)) ; + for(int i = 0 ; i < n ; ++i){ + for(int j = 0 ; j < m ; ++j){ + cin >> mat[i][j] ; + } + } + int sum = 0 ; + function f = [&](int i, int j) -> int { + if(i >= n || j >= m) return 0 ; + if(dp[i][j] != -1) return dp[i][j] ; + dp[i][j] = max(f(i + 1 , j) , f(i , j + 1)) + mat[i][j] ; + return dp[i][j] ; + }; + cout << f(0 , 0) << nl ; + // cout << sum << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/Y_Problems/Y. Number of Ways/.cph/.1.cpp_4379887a510be74b074559e430e8e361.prob b/Codeforces_Problem_Solving/Y_Problems/Y. Number of Ways/.cph/.1.cpp_4379887a510be74b074559e430e8e361.prob new file mode 100644 index 0000000..74a6079 --- /dev/null +++ b/Codeforces_Problem_Solving/Y_Problems/Y. Number of Ways/.cph/.1.cpp_4379887a510be74b074559e430e8e361.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\Y_Problems\\Y. Number of Ways\\1.cpp","tests":[{"id":1687803214803,"input":"2 5","output":"4"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\Y_Problems\\Y. Number of Ways\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/Y_Problems/Y. Number of Ways/1.bin b/Codeforces_Problem_Solving/Y_Problems/Y. Number of Ways/1.bin new file mode 100644 index 0000000..602ef9c Binary files /dev/null and b/Codeforces_Problem_Solving/Y_Problems/Y. Number of Ways/1.bin differ diff --git a/Codeforces_Problem_Solving/Y_Problems/Y. Number of Ways/1.cpp b/Codeforces_Problem_Solving/Y_Problems/Y. Number of Ways/1.cpp new file mode 100644 index 0000000..163de79 --- /dev/null +++ b/Codeforces_Problem_Solving/Y_Problems/Y. Number of Ways/1.cpp @@ -0,0 +1,122 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int S , E ; + cin >> S >> E ; + int cnt = 0 ; + function f = [&](int sum) -> void { + if(sum == E){ + cnt += 1 ; + return ; + } + if(sum > E) { + return ; + } + f(sum + 1) ; + f(sum + 2) ; + f(sum + 3) ; + return ; + }; + f(S) ; + cout << cnt << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file diff --git a/Codeforces_Problem_Solving/Z_Problems/Z. Left Max/.cph/.1.cpp_5b7d2184b4ed883ff1a02289fa446ab5.prob b/Codeforces_Problem_Solving/Z_Problems/Z. Left Max/.cph/.1.cpp_5b7d2184b4ed883ff1a02289fa446ab5.prob new file mode 100644 index 0000000..dad098c --- /dev/null +++ b/Codeforces_Problem_Solving/Z_Problems/Z. Left Max/.cph/.1.cpp_5b7d2184b4ed883ff1a02289fa446ab5.prob @@ -0,0 +1 @@ +{"name":"Local: 1","url":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\Z_Problems\\Z. Left Max\\1.cpp","tests":[{"id":1687197443682,"input":"5\n4 3 5 7 3\n","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\varsh\\.vscode\\nayan work c c++\\Codeforces_Problem_Solving\\Z_Problems\\Z. Left Max\\1.cpp","group":"local","local":true} \ No newline at end of file diff --git a/Codeforces_Problem_Solving/Z_Problems/Z. Left Max/1.bin b/Codeforces_Problem_Solving/Z_Problems/Z. Left Max/1.bin new file mode 100644 index 0000000..d800fc4 Binary files /dev/null and b/Codeforces_Problem_Solving/Z_Problems/Z. Left Max/1.bin differ diff --git a/Codeforces_Problem_Solving/Z_Problems/Z. Left Max/1.cpp b/Codeforces_Problem_Solving/Z_Problems/Z. Left Max/1.cpp new file mode 100644 index 0000000..093627e --- /dev/null +++ b/Codeforces_Problem_Solving/Z_Problems/Z. Left Max/1.cpp @@ -0,0 +1,116 @@ +#include +using namespace std; + +// Policy based data structures(PBDS) C++ STL +// order_of_key(k): returns count of elements strictly smaller than k +// find_by_order(k): returns the iterator of the k-th element in a set (0-index) +// Time complexity: O(logn) for both +#include +#include +using namespace __gnu_pbds; +typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; + +#ifndef ONLINE_JUDGE +#define debug(x) cerr << #x <<" "; _print(x); cerr << endl; +#else +#define debug(x) +#endif + +void _print(long long t) {cerr << t;} +void _print(string t) {cerr << t;} +void _print(char t) {cerr << t;} +void _print(long double t) {cerr << t;} + +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + +#define ll long long +#define int ll +#define ld long double +#define iv(a , n) vectora(n); for(int i=0;i>a[i];} +#define yes cout << "YES" << endl; +#define no cout << "NO" << endl; +#define all(v) v.begin(),v.end() +#define F first +#define S second +#define check1(v) for(auto &i : v){ cout< isPrime(N , 1) ; +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; // a random number generator (RNG) using the Mersenne Twister algorithm, specifically the mt19937 engine. The purpose of an RNG is to generate a sequence of random numbers. + +int gcd(int a, int b){if(b == 0){return a;} return gcd(b, a % b);} +int lcm(int a, int b){return (a / gcd(a, b) * b) ;} +bool comparatorfunction(pair &a, pair &b){if(a.S != b.S){return a.S < b.S ;}return a.F > b.F ;} +int power(int x, int y){int res = 1 ; while(y > 0) {if(y & 1) res = (res * x) ; x = (x * x) ; y = y >> 1 ;} return res ;} +int powermod(int x, int y){int res = 1; x = x % mod97; while(y > 0){if(y&1) res = (res * x) % mod97; y = y >> 1; x = (x * x) % mod97 ;}return res ;} +bool isPowerOfTwo(int n){if(n==0) {return false;} return (ceil(log2(n)) == floor(log2(n)));} +void prime(){isPrime[0]=isPrime[1]=false;for(int i = 2; i <= N; ++i){if(isPrime[i] == true){for(int j = 2*i; j <= N; j += i){isPrime[j] = false;}}}} +void spf(){for(int i = 0; i <= N; ++i) SPF[i] = i; for(int i = 2; i <= N; ++i) if(SPF[i] == i) for(int j = i; j <= N; j += i) if(SPF[j] == j) SPF[j] = i;} // SPF is the smallest prime number that divides a given number without leaving a remainder +int isqrt(int n){long long x = sqrtl(n);while (x*x>n){--x;} while((x+1) * (x+1)<=n){++x;}return x;} +int sqrtprecision(int l,int r,int target){while(r-l>EPS){int mid=(l+(r-l)/2);if(mid*mid&a,int target){int ans=-1; while(l <= r){int mid=(l+(r-l)/2); if(a[mid]==target){ans=mid;return ans;}if(a[mid](l, r)(rng);} + +bool solve(){ + int n ; + cin >> n ; + iv(v , n) + int mx = v[0] ; + function f = [&](int i) -> void { + if(i == n) return ; + mx = max(mx , v[i]) ; + cout << mx << " " ; + f(i + 1) ; + }; + f(0) ; + cout << nl ; + return true; +} + + +int32_t main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); +//#ifndef ONLINE_JUDGE +// freopen("input.txt","r",stdin); +// freopen("output.txt","w",stdout); +// freopen("error.txt", "w", stderr); +//#endif + int t = 1; + //cin >> t; + //int count = 1; + + while (t--){ + //cout << "Case #" << count << ": "; + if(solve()){ + //count++; + }else{ + // cout << "NO" << endl; + } + } + return 0; +} + + + + + \ No newline at end of file