Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code : Least Product

#include <bits/stdc++.h>
using namespace std;

void solve(vector<int> &a) {
    int n = a.size();
    int neg_count = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            cout << 0 << endl;
            return;
        }
        if (a[i] < 0) {
            neg_count++;
        }
    }

    // Product is positive. Set the first integer to zero.
    if (neg_count % 2 == 0) {
        cout << 1 << endl;
        cout << 1 << " " << 0 << endl;
        return;
    }

    // Product is negative. Do nothing.
    cout << 0 << endl;
    return;
}

int main() {
    int t;
    cin >> t;

    for (int zz = 0; zz < t; zz++) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        solve(a);
    }
    return 0;
}