Codeforces Round #838 (Div. 2) 1762A - Divide and Conquer Solution


  

Problem Link: https://codeforces.com/contest/1762/problem/A

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int main() {
  10. int t;
  11. cin >> t;
  12. while (t--) {
  13. int n;
  14. cin >> n;
  15. vector<int> v(n + 1);
  16. int sum = 0;
  17. for (int i = 0; i < n; i++) {
  18. cin >> v[i];
  19. sum += v[i];
  20. }
  21. if (sum % 2 == 0) {
  22. cout << "0" << endl;
  23. continue;
  24. }
  25. int ans = INT_MAX;
  26. for (int i = 0; i < n; i++) {
  27. if (v[i] % 2 == 0) {
  28. int cn = 0;
  29. int a = v[i];
  30. while (a > 0 && (a % 2 == 0)) {
  31. a /= 2;
  32. cn++;
  33. }
  34. ans = min(ans, cn);
  35. }
  36. }
  37. for (int i = 0; i < n; i++) {
  38. if (v[i] % 2 == 1) {
  39. int cn = 0;
  40. int a = v[i];
  41. while (a % 2 == 1) {
  42. a /= 2;
  43. cn++;
  44. }
  45. ans = min(ans, cn);
  46. }
  47. }
  48. cout << ans << endl;
  49. }
  50. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.