Cod sursa(job #2856278)

Utilizator Xutzu358Ignat Alex Xutzu358 Data 23 februarie 2022 17:34:22
Problema Jocul Flip Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("flip.in");
ofstream g("flip.out");

int n,m;
int mat[18][18];
int summax;
int s,stot;

void read() {
    f >> n >> m;
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++) {
            f >> mat[i][j];
        }
    }
}

void solve() {
    for (int p=0;p<(1<<m);p++) {
        stot = 0;
        for (int i=1;i<=n;i++) {
            s = 0;
            for (int j=1;j<=m;j++) {
                if (p&(1<<(j-1))) {
                    s -= mat[i][j];
                }
                else {
                    s += mat[i][j];
                }
            }
            stot += abs(s);
        }
        summax = max(summax,stot);
    }
    g << summax;
}
int main()
{
    read();
    solve();
    return 0;
}