From 37b7e815612dec5655d2ee2363835e2075701ae6 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Wed, 29 Jun 2022 21:03:53 +0200 Subject: Solved the first 6 problems of codechef Starters --- codechef/AjdacentSumParity/inp | 0 codechef/AjdacentSumParity/main | Bin 0 -> 27320 bytes codechef/AjdacentSumParity/main.cpp | 26 +++++++++++++ codechef/AjdacentSumParity/main_input0.txt | 9 +++++ codechef/AjdacentSumParity/main_output0.txt | 4 ++ codechef/BestOfTwo/inp | 0 codechef/BestOfTwo/main | Bin 0 -> 22624 bytes codechef/BestOfTwo/main.cpp | 15 ++++++++ codechef/BestOfTwo/main_input0.txt | 5 +++ codechef/BestOfTwo/main_output0.txt | 4 ++ codechef/ChangeRowAndColumnBoth/inp | 0 codechef/ChangeRowAndColumnBoth/main | Bin 0 -> 22576 bytes codechef/ChangeRowAndColumnBoth/main.cpp | 19 +++++++++ codechef/ChangeRowAndColumnBoth/main_input0.txt | 5 +++ codechef/ChangeRowAndColumnBoth/main_output0.txt | 4 ++ codechef/DenseBracketSequence/main | Bin 39024 -> 24880 bytes codechef/DenseBracketSequence/main.cpp | 24 ++++-------- codechef/EvenEqualOdd/inp | 0 codechef/EvenEqualOdd/main | Bin 0 -> 46120 bytes codechef/EvenEqualOdd/main.cpp | 47 +++++++++++++++++++++++ codechef/EvenEqualOdd/main_input0.txt | 7 ++++ codechef/EvenEqualOdd/main_input1.txt | 3 ++ codechef/EvenEqualOdd/main_output0.txt | 3 ++ codechef/EvenEqualOdd/main_output1.txt | 1 + codechef/RetriveTheArray/inp | 0 codechef/RetriveTheArray/main | Bin 0 -> 27480 bytes codechef/RetriveTheArray/main.cpp | 28 ++++++++++++++ codechef/RetriveTheArray/main_input0.txt | 9 +++++ codechef/RetriveTheArray/main_output0.txt | 4 ++ codechef/XorAndMultiply/inp | 0 codechef/XorAndMultiply/main | Bin 0 -> 43776 bytes codechef/XorAndMultiply/main.cpp | 26 +++++++++++++ codechef/XorAndMultiply/main_input0.txt | 4 ++ codechef/XorAndMultiply/main_output0.txt | 3 ++ codechef/chefAndHisApps/inp | 0 codechef/chefAndHisApps/main | Bin 0 -> 22624 bytes codechef/chefAndHisApps/main.cpp | 33 ++++++++++++++++ codechef/chefAndHisApps/main_input0.txt | 5 +++ codechef/chefAndHisApps/main_output0.txt | 4 ++ 39 files changed, 276 insertions(+), 16 deletions(-) create mode 100644 codechef/AjdacentSumParity/inp create mode 100755 codechef/AjdacentSumParity/main create mode 100644 codechef/AjdacentSumParity/main.cpp create mode 100644 codechef/AjdacentSumParity/main_input0.txt create mode 100644 codechef/AjdacentSumParity/main_output0.txt create mode 100644 codechef/BestOfTwo/inp create mode 100755 codechef/BestOfTwo/main create mode 100644 codechef/BestOfTwo/main.cpp create mode 100644 codechef/BestOfTwo/main_input0.txt create mode 100644 codechef/BestOfTwo/main_output0.txt create mode 100644 codechef/ChangeRowAndColumnBoth/inp create mode 100755 codechef/ChangeRowAndColumnBoth/main create mode 100644 codechef/ChangeRowAndColumnBoth/main.cpp create mode 100644 codechef/ChangeRowAndColumnBoth/main_input0.txt create mode 100644 codechef/ChangeRowAndColumnBoth/main_output0.txt create mode 100644 codechef/EvenEqualOdd/inp create mode 100755 codechef/EvenEqualOdd/main create mode 100644 codechef/EvenEqualOdd/main.cpp create mode 100644 codechef/EvenEqualOdd/main_input0.txt create mode 100644 codechef/EvenEqualOdd/main_input1.txt create mode 100644 codechef/EvenEqualOdd/main_output0.txt create mode 100644 codechef/EvenEqualOdd/main_output1.txt create mode 100644 codechef/RetriveTheArray/inp create mode 100755 codechef/RetriveTheArray/main create mode 100644 codechef/RetriveTheArray/main.cpp create mode 100644 codechef/RetriveTheArray/main_input0.txt create mode 100644 codechef/RetriveTheArray/main_output0.txt create mode 100644 codechef/XorAndMultiply/inp create mode 100755 codechef/XorAndMultiply/main create mode 100644 codechef/XorAndMultiply/main.cpp create mode 100644 codechef/XorAndMultiply/main_input0.txt create mode 100644 codechef/XorAndMultiply/main_output0.txt create mode 100644 codechef/chefAndHisApps/inp create mode 100755 codechef/chefAndHisApps/main create mode 100644 codechef/chefAndHisApps/main.cpp create mode 100644 codechef/chefAndHisApps/main_input0.txt create mode 100644 codechef/chefAndHisApps/main_output0.txt diff --git a/codechef/AjdacentSumParity/inp b/codechef/AjdacentSumParity/inp new file mode 100644 index 0000000..e69de29 diff --git a/codechef/AjdacentSumParity/main b/codechef/AjdacentSumParity/main new file mode 100755 index 0000000..c642716 Binary files /dev/null and b/codechef/AjdacentSumParity/main differ 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 + +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 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 diff --git a/codechef/BestOfTwo/main b/codechef/BestOfTwo/main new file mode 100755 index 0000000..571ccd9 Binary files /dev/null and b/codechef/BestOfTwo/main differ 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 + +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 diff --git a/codechef/ChangeRowAndColumnBoth/main b/codechef/ChangeRowAndColumnBoth/main new file mode 100755 index 0000000..e801a86 Binary files /dev/null and b/codechef/ChangeRowAndColumnBoth/main differ 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 + +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 index 4682a3d..74af562 100755 Binary files a/codechef/DenseBracketSequence/main and b/codechef/DenseBracketSequence/main differ 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 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 diff --git a/codechef/EvenEqualOdd/main b/codechef/EvenEqualOdd/main new file mode 100755 index 0000000..f246ca1 Binary files /dev/null and b/codechef/EvenEqualOdd/main differ 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 + +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 v(n * 2); + vector 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 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 diff --git a/codechef/RetriveTheArray/main b/codechef/RetriveTheArray/main new file mode 100755 index 0000000..c45f726 Binary files /dev/null and b/codechef/RetriveTheArray/main differ 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 + +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 v(n); + long long sum = 0; + for(auto &x : v){ + cin >> x; + sum += x; + } + vector 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 diff --git a/codechef/XorAndMultiply/main b/codechef/XorAndMultiply/main new file mode 100755 index 0000000..a2063ee Binary files /dev/null and b/codechef/XorAndMultiply/main differ 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 + +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 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 diff --git a/codechef/chefAndHisApps/main b/codechef/chefAndHisApps/main new file mode 100755 index 0000000..5e05251 Binary files /dev/null and b/codechef/chefAndHisApps/main differ 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 + +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 -- cgit v1.2.3