Cod sursa(job #2785501)

Utilizator gamergodGamer God gamergod Data 18 octombrie 2021 19:44:14
Problema Jocul Flip Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <iostream>
#include <fstream>
using namespace std;

short N, M;
long long a, b;
long long m[17][17] = { 0 }, sum;

int main() {
	ifstream in("flip.in"); // take input
	ofstream out("flip.out"); // give output

	in >> N >> M; // dimensiumile matricei


	for (short i = 0; i < N; i++) {
		for (short j = 0; j < M; j++) {
			in >> m[i][j];
		}
	}
	
	for (short i = 0; i < M; i++) {
		a = 0; b = 0;
		for (short j = 0; j < N; ++j) {
			a += m[j][i];
			b += -1 * m[j][i];
		}

		if (a < b) {
		for (short x = 0; x < N; x++) {
		m[x][i] = -1 * m[x][i];
		}
	}

	} 
	for (short z = 0; z < N; ++z) {
		a = 0; b = 0;
		for (short c = 0; c < M; c++) {
			a += m[z][c];
			b += -1 * m[z][c];
		}
		if (b > a) {
			for (short x = 0; x < M; x++) {
				m[z][x] = -1 * m[z][x];
			}
		}
	}
	for (a = 0; a < N; a++) {
		for ( b = 0; b < M; b++) {
			sum += m[a][b];
		}
	} out << sum;



}