Cod sursa(job #3322693)

Utilizator MihneaStoicaMihnea Teodor Stoica MihneaStoica Data 15 noiembrie 2025 11:19:17
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;

#if 1
#define int ll
#define uint ull
#endif

/**
 * Problem: Jocul Flip
 * URL: https://infoarena.ro/problema/flip
 * TL: 75 ms
 * ML: 64 MB
 *
 * Good Luck!
*/

void tc() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> a[i][j];

    int sol = 0;

    for (int mask = 0; mask < (1 << n); mask++) {
        int sumTotal = 0;

        for (int j = 0; j < m; j++) {
            int colSum = 0;

            for (int i = 0; i < n; i++) {
                int val = a[i][j];
                if (mask & (1 << i)) val = -val;
                colSum += val;
            }

            sumTotal += llabs(colSum);
        }

        sol = max(sol, sumTotal);
    }

    cout << sol << '\n';
}

#define MTC 0
#define FIO 1
#define FN "flip"

signed main() {
#if FIO == 1 && !defined(LOCAL)
    (void)freopen(FN ".in", "r", stdin);
    (void)freopen(FN ".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#if MTC == 1
    signed tt; cin >> tt;
    while (tt --) tc();
#else
    tc();
#endif
    return 0;
}