Codeforces Round #838 (Div. 2) 1762A - Divide and Conquer Solution
Problem Link: https://codeforces.com/contest/1762/problem/A
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int t;
- cin >> t;
- while (t--) {
- int n;
- cin >> n;
- vector<int> v(n + 1);
- int sum = 0;
- for (int i = 0; i < n; i++) {
- cin >> v[i];
- sum += v[i];
- }
- if (sum % 2 == 0) {
- cout << "0" << endl;
- continue;
- }
- int ans = INT_MAX;
- for (int i = 0; i < n; i++) {
- if (v[i] % 2 == 0) {
- int cn = 0;
- int a = v[i];
- while (a > 0 && (a % 2 == 0)) {
- a /= 2;
- cn++;
- }
- ans = min(ans, cn);
- }
- }
- for (int i = 0; i < n; i++) {
- if (v[i] % 2 == 1) {
- int cn = 0;
- int a = v[i];
- while (a % 2 == 1) {
- a /= 2;
- cn++;
- }
- ans = min(ans, cn);
- }
- }
- cout << ans << endl;
- }
- }
No comments