Cod sursa(job #3269803)

Utilizator vvalentinCiun Valentin vvalentin Data 20 ianuarie 2025 20:50:47
Problema Jocul Flip Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin ("flip.in");
ofstream fout ("flip.out");
int n, m, s, ans, v[20][20], il, ic, x;
bool l[20], c[20];
int main() {
    fin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            fin >> v[i][j];
        }
    }
    while (!l[n]) {
        while (l[il]) {
            l[il++] = 0;
        }
        l[il] = 1;
        ic = 0;
        c[m] = 0;
        while(!c[m]) {
            while (c[ic]) {
                c[ic++] = 0;
            }
            c[ic] = 1;
            s = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    x = v[i][j];
                    if (i == il) x = -x;
                    if (j == ic) x = -x;
                    s += x;
                }
            }
            ans = max(ans, s);
        }

    }
    fout << ans;

    return 0;
}