Cod sursa(job #1557637)

Utilizator lechiorStanislav lechior Data 27 decembrie 2015 22:11:08
Problema Jocul Flip Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <iostream>
#include <fstream>

using namespace std;

#define MAX_map 18

int map[MAX_map][MAX_map];
int m, n; // n linii m coloane
long int maxa;

long int summ()
{
	long int s = 0;
	for( int y = 0; y < n; y++ )
		for( int x = 0; x < m; x++ )
			s += map[x][y]; 
	return s;
}

long int WhatLine( int x, int y )
{
	long int s_x = 0;
	long int s_y = 0;
	
	for( int i = 0; i < m; i++ ) // summ for x
		s_x += -map[i][y];
		
	for( int i = 0; i < n; i++ ) // summ for y
		s_y += -map[x][i];

	if( s_x > s_y )
	{
		for( int i = 0; i < m; i++ ) // summ for x
			map[i][y] = -map[i][y];
	} else 
	{
		for( int i = 0; i < n; i++ ) // summ for y
			map[x][i] = -map[x][i];
	}
	return summ();
}

int main()
{
	ifstream f("flip.in");
	f >> n >> m;
	for( int y = 0; y < n; y++ )
		for( int x = 0; x < m; x++ )
			f >> map[x][y];
	f.close();
	
	maxa = WhatLine(0, 0);
	for(int q=0; q<m*n; q++)
	for(int w=0; w<m*n; w++)
	for(int i=0; i<m*n; i++)
	for( int y = 0; y < n; y++ )
		for( int x = 0; x < m; x++ )
		{
			long int loc_max = WhatLine(x, y);	
			if( loc_max > maxa )
				maxa = loc_max;
		}
		
	
	ofstream ff("flip.out");
		ff << maxa;
	ff.close();
	return 0;
}