Cod sursa(job #1841745)

Utilizator YukisoRoland Fazakas Yukiso Data 5 ianuarie 2017 22:46:08
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>

using namespace std;

int N,M,a[20][20];

int flip(int n,int m){
	int sum1=0,sum2=0,SUM=0;
	
	for(int i=0; i<n; i++){
		
		for(int j=0; j<m; j++){
			
			sum1+=a[i][j];
			sum2-=a[i][j];
		
		}
		
		if(sum1<sum2)		
			
			for(int j=0; j<m; j++)
			
				a[i][j]=-a[i][j];

	}	
	
	for(int j=0; j<m; j++){
		
		for(int i=0; i<n; i++){
			
			sum1+=a[i][j];
			sum2-=a[i][j];
		
		}
		
		if(sum1<sum2){		
			
			for(int i=0; i<n; i++)
			
				a[i][j]=-a[i][j];
		SUM+=sum2;
		}
		else SUM+=sum1;
		sum1=0;
		sum2=0;
	}




	return SUM;
}

int main(){
	ifstream file ("flip.in");
	ofstream file_o ("flip.out"); 
	file>>N>>M;
	for(int i=0; i<N; i++)
		for(int j=0; j<M; j++)
			file>>a[i][j];
	file_o<<flip(N,M);
}