diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2022-06-29 21:03:53 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2022-06-29 21:03:53 +0200 |
| commit | 37b7e815612dec5655d2ee2363835e2075701ae6 (patch) | |
| tree | 5c0b5e5fcf0c383c0e63c5c86524334630b35139 | |
| parent | 1b8f7c9d4eb8b767d32dbbbfd96662b73c037627 (diff) | |
| download | competitive-programming-37b7e815612dec5655d2ee2363835e2075701ae6.tar.xz competitive-programming-37b7e815612dec5655d2ee2363835e2075701ae6.zip | |
Solved the first 6 problems of codechef Starters
39 files changed, 276 insertions, 16 deletions
diff --git a/codechef/AjdacentSumParity/inp b/codechef/AjdacentSumParity/inp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/codechef/AjdacentSumParity/inp diff --git a/codechef/AjdacentSumParity/main b/codechef/AjdacentSumParity/main Binary files differnew file mode 100755 index 0000000..c642716 --- /dev/null +++ b/codechef/AjdacentSumParity/main diff --git a/codechef/AjdacentSumParity/main.cpp b/codechef/AjdacentSumParity/main.cpp new file mode 100644 index 0000000..899003a --- /dev/null +++ b/codechef/AjdacentSumParity/main.cpp @@ -0,0 +1,26 @@ +#include<bits/stdc++.h> + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int n; + cin >> n; + vector<int> v(n); + int sum = 0; + for(int &x : v) { + cin >> x; + sum += x; + } + if(sum % 2 == 0) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + + } +} diff --git a/codechef/AjdacentSumParity/main_input0.txt b/codechef/AjdacentSumParity/main_input0.txt new file mode 100644 index 0000000..12bae4c --- /dev/null +++ b/codechef/AjdacentSumParity/main_input0.txt @@ -0,0 +1,9 @@ +4 +2 +0 0 +2 +1 0 +4 +1 0 1 0 +3 +1 0 0 diff --git a/codechef/AjdacentSumParity/main_output0.txt b/codechef/AjdacentSumParity/main_output0.txt new file mode 100644 index 0000000..2bc7799 --- /dev/null +++ b/codechef/AjdacentSumParity/main_output0.txt @@ -0,0 +1,4 @@ +YES +NO +YES +NO diff --git a/codechef/BestOfTwo/inp b/codechef/BestOfTwo/inp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/codechef/BestOfTwo/inp diff --git a/codechef/BestOfTwo/main b/codechef/BestOfTwo/main Binary files differnew file mode 100755 index 0000000..571ccd9 --- /dev/null +++ b/codechef/BestOfTwo/main diff --git a/codechef/BestOfTwo/main.cpp b/codechef/BestOfTwo/main.cpp new file mode 100644 index 0000000..f2961f0 --- /dev/null +++ b/codechef/BestOfTwo/main.cpp @@ -0,0 +1,15 @@ +#include<bits/stdc++.h> + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int x, y; + cin >> x >> y; + cout << max(x, y) << endl; + } +} diff --git a/codechef/BestOfTwo/main_input0.txt b/codechef/BestOfTwo/main_input0.txt new file mode 100644 index 0000000..3d8197a --- /dev/null +++ b/codechef/BestOfTwo/main_input0.txt @@ -0,0 +1,5 @@ +4 +40 60 +67 55 +50 50 +1 100 diff --git a/codechef/BestOfTwo/main_output0.txt b/codechef/BestOfTwo/main_output0.txt new file mode 100644 index 0000000..da1a975 --- /dev/null +++ b/codechef/BestOfTwo/main_output0.txt @@ -0,0 +1,4 @@ +60 +67 +50 +100 diff --git a/codechef/ChangeRowAndColumnBoth/inp b/codechef/ChangeRowAndColumnBoth/inp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/codechef/ChangeRowAndColumnBoth/inp diff --git a/codechef/ChangeRowAndColumnBoth/main b/codechef/ChangeRowAndColumnBoth/main Binary files differnew file mode 100755 index 0000000..e801a86 --- /dev/null +++ b/codechef/ChangeRowAndColumnBoth/main diff --git a/codechef/ChangeRowAndColumnBoth/main.cpp b/codechef/ChangeRowAndColumnBoth/main.cpp new file mode 100644 index 0000000..6cff4f0 --- /dev/null +++ b/codechef/ChangeRowAndColumnBoth/main.cpp @@ -0,0 +1,19 @@ +#include<bits/stdc++.h> + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int sx, sy, ex, ey; + cin >> sx >> sy >> ex >> ey; + if(sx != ex && sy != ey) { + cout << 1 << endl; + } else { + cout << 2 << endl; + } + } +} diff --git a/codechef/ChangeRowAndColumnBoth/main_input0.txt b/codechef/ChangeRowAndColumnBoth/main_input0.txt new file mode 100644 index 0000000..ff56c91 --- /dev/null +++ b/codechef/ChangeRowAndColumnBoth/main_input0.txt @@ -0,0 +1,5 @@ +4 +1 2 9 8 +5 5 5 7 +8 6 6 8 +3 10 8 10 diff --git a/codechef/ChangeRowAndColumnBoth/main_output0.txt b/codechef/ChangeRowAndColumnBoth/main_output0.txt new file mode 100644 index 0000000..099b7d9 --- /dev/null +++ b/codechef/ChangeRowAndColumnBoth/main_output0.txt @@ -0,0 +1,4 @@ +1 +2 +1 +2 diff --git a/codechef/DenseBracketSequence/main b/codechef/DenseBracketSequence/main Binary files differindex 4682a3d..74af562 100755 --- a/codechef/DenseBracketSequence/main +++ b/codechef/DenseBracketSequence/main diff --git a/codechef/DenseBracketSequence/main.cpp b/codechef/DenseBracketSequence/main.cpp index 6785a12..e26df3c 100644 --- a/codechef/DenseBracketSequence/main.cpp +++ b/codechef/DenseBracketSequence/main.cpp @@ -12,22 +12,14 @@ int main() { cin >> n; string s; cin >> s; - int count = 0; - stack<char> st; - st.push(s[0]); - for(int i = 1; i < n; i++) { - if(s[i] == '(') { - st.push('('); - } - if(s[i] == ')') { - if(st.top() == '(' && !st.empty()){ - st.pop(); - count++; - } - } + int cls = count(s.begin(), s.end(), ')'); + int opn = 0; + int ans = 0; + for (int i = 0; i < n; i++) { + cls -= (s[i] == ')'); + opn += (s[i] == '('); + ans = max(ans, min(opn, cls)); } - cout << count << endl; + cout << n - ans * 2 << endl; } } - - diff --git a/codechef/EvenEqualOdd/inp b/codechef/EvenEqualOdd/inp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/codechef/EvenEqualOdd/inp diff --git a/codechef/EvenEqualOdd/main b/codechef/EvenEqualOdd/main Binary files differnew file mode 100755 index 0000000..f246ca1 --- /dev/null +++ b/codechef/EvenEqualOdd/main diff --git a/codechef/EvenEqualOdd/main.cpp b/codechef/EvenEqualOdd/main.cpp new file mode 100644 index 0000000..9880c37 --- /dev/null +++ b/codechef/EvenEqualOdd/main.cpp @@ -0,0 +1,47 @@ +#include<bits/stdc++.h> + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int n; + cin >> n; + vector<int> v(n * 2); + vector<int> even; + int ev = 0; + int odd = 0; + for(int &x : v) { + cin >> x; + ev += (x % 2 == 0); + odd += (x % 2 != 0); + if(x % 2 == 0) { + even.push_back(x); + } + } + vector<int> op; + for(int i = 0; i < even.size(); i++) { + int count = 1; + while((even[i] / 2 % 2) != 1) { + count++; + even[i] /= 2; + } + op.push_back(count); + } + sort(op.begin(), op.end()); + if(ev == odd) { + cout << 0 << endl; + } else if(ev > odd){ + int ans = 0; + for(int i = 0; i < (ev - odd) / 2; i++) { + ans += op[i]; + } + cout << ans << endl; + } else { + cout << abs(ev - odd) / 2 << endl; + } + } +} diff --git a/codechef/EvenEqualOdd/main_input0.txt b/codechef/EvenEqualOdd/main_input0.txt new file mode 100644 index 0000000..b63c2ad --- /dev/null +++ b/codechef/EvenEqualOdd/main_input0.txt @@ -0,0 +1,7 @@ +3 +3 +1 2 3 4 5 6 +3 +1 3 4 8 2 6 +3 +1 5 3 5 6 7 diff --git a/codechef/EvenEqualOdd/main_input1.txt b/codechef/EvenEqualOdd/main_input1.txt new file mode 100644 index 0000000..f57d886 --- /dev/null +++ b/codechef/EvenEqualOdd/main_input1.txt @@ -0,0 +1,3 @@ +1 +1 +1 1
\ No newline at end of file diff --git a/codechef/EvenEqualOdd/main_output0.txt b/codechef/EvenEqualOdd/main_output0.txt new file mode 100644 index 0000000..4539bbf --- /dev/null +++ b/codechef/EvenEqualOdd/main_output0.txt @@ -0,0 +1,3 @@ +0 +1 +2 diff --git a/codechef/EvenEqualOdd/main_output1.txt b/codechef/EvenEqualOdd/main_output1.txt new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/codechef/EvenEqualOdd/main_output1.txt @@ -0,0 +1 @@ +1
\ No newline at end of file diff --git a/codechef/RetriveTheArray/inp b/codechef/RetriveTheArray/inp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/codechef/RetriveTheArray/inp diff --git a/codechef/RetriveTheArray/main b/codechef/RetriveTheArray/main Binary files differnew file mode 100755 index 0000000..c45f726 --- /dev/null +++ b/codechef/RetriveTheArray/main diff --git a/codechef/RetriveTheArray/main.cpp b/codechef/RetriveTheArray/main.cpp new file mode 100644 index 0000000..491e6db --- /dev/null +++ b/codechef/RetriveTheArray/main.cpp @@ -0,0 +1,28 @@ +#include<bits/stdc++.h> + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int n; + cin >> n; + vector<long long> v(n); + long long sum = 0; + for(auto &x : v){ + cin >> x; + sum += x; + } + vector<long long> ans(n); + for(int i = 0; i < n; i++) { + ans[i] = v[i] - sum / (n + 1); + } + for(auto x : ans) { + cout << x << " "; + } + cout << endl; + } +} diff --git a/codechef/RetriveTheArray/main_input0.txt b/codechef/RetriveTheArray/main_input0.txt new file mode 100644 index 0000000..bfebcbe --- /dev/null +++ b/codechef/RetriveTheArray/main_input0.txt @@ -0,0 +1,9 @@ +4 +1 +6 +3 +7 8 9 +4 +13 15 13 14 +2 +25 20 diff --git a/codechef/RetriveTheArray/main_output0.txt b/codechef/RetriveTheArray/main_output0.txt new file mode 100644 index 0000000..3110f5d --- /dev/null +++ b/codechef/RetriveTheArray/main_output0.txt @@ -0,0 +1,4 @@ +3 +1 2 3 +2 4 2 3 +10 5 diff --git a/codechef/XorAndMultiply/inp b/codechef/XorAndMultiply/inp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/codechef/XorAndMultiply/inp diff --git a/codechef/XorAndMultiply/main b/codechef/XorAndMultiply/main Binary files differnew file mode 100755 index 0000000..a2063ee --- /dev/null +++ b/codechef/XorAndMultiply/main diff --git a/codechef/XorAndMultiply/main.cpp b/codechef/XorAndMultiply/main.cpp new file mode 100644 index 0000000..0d557ca --- /dev/null +++ b/codechef/XorAndMultiply/main.cpp @@ -0,0 +1,26 @@ +#include<bits/stdc++.h> + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int n = 0; + cin >> n; + long long a, b; + cin >> a >> b; + int mx = 0; + map<int, int> mp; + for(int i = 0; i < int(pow(2, n));i++) { + int l = a ^ i; + int r = b ^ i; + mx = max(mx, l * r); + cerr << mx << " " << i << endl; + mp[mx] = i; + } + cout << mp[mx] << endl; + } +} diff --git a/codechef/XorAndMultiply/main_input0.txt b/codechef/XorAndMultiply/main_input0.txt new file mode 100644 index 0000000..3726bfd --- /dev/null +++ b/codechef/XorAndMultiply/main_input0.txt @@ -0,0 +1,4 @@ +3 +1 0 0 +3 4 6 +2 2 1 diff --git a/codechef/XorAndMultiply/main_output0.txt b/codechef/XorAndMultiply/main_output0.txt new file mode 100644 index 0000000..983374a --- /dev/null +++ b/codechef/XorAndMultiply/main_output0.txt @@ -0,0 +1,3 @@ +1 +3 +0 diff --git a/codechef/chefAndHisApps/inp b/codechef/chefAndHisApps/inp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/codechef/chefAndHisApps/inp diff --git a/codechef/chefAndHisApps/main b/codechef/chefAndHisApps/main Binary files differnew file mode 100755 index 0000000..5e05251 --- /dev/null +++ b/codechef/chefAndHisApps/main diff --git a/codechef/chefAndHisApps/main.cpp b/codechef/chefAndHisApps/main.cpp new file mode 100644 index 0000000..8d38e22 --- /dev/null +++ b/codechef/chefAndHisApps/main.cpp @@ -0,0 +1,33 @@ +#include <bits/stdc++.h> + +using namespace std; + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + int s, x, y, z; + cin >> s >> x >> y >> z; + int xy = x + y; + int free = s - xy; + int count = 0; + int mx = max(x, y); + // 3 <= 7 + if (z <= free) { + cout << 0 << endl; + } else { + while (z > free) { + z -= max(x, y); + if (x > y) { + x = 0; + } else { + y = 0; + } + count++; + } + cout << count << endl; + } + } +} diff --git a/codechef/chefAndHisApps/main_input0.txt b/codechef/chefAndHisApps/main_input0.txt new file mode 100644 index 0000000..0d4d54e --- /dev/null +++ b/codechef/chefAndHisApps/main_input0.txt @@ -0,0 +1,5 @@ +4 +10 1 2 3 +9 4 5 1 +15 5 10 15 +100 20 30 75 diff --git a/codechef/chefAndHisApps/main_output0.txt b/codechef/chefAndHisApps/main_output0.txt new file mode 100644 index 0000000..93e26d2 --- /dev/null +++ b/codechef/chefAndHisApps/main_output0.txt @@ -0,0 +1,4 @@ +0 +1 +2 +1 |
