Mai intai trebuie sa te autentifici.
Cod sursa(job #2655471)
| Utilizator | Data | 4 octombrie 2020 14:53:02 | |
|---|---|---|---|
| Problema | Jocul Flip | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 1.47 kb |
#include <bits/stdc++.h>
using namespace std;
FILE *f=fopen("flip.in","r");
FILE *g=fopen("flip.out","w");
int M[17][17]={0};
int A[17][17]={0};
int n,m,k,p;
bool MaxL(int i,int M[17][17]){long long int s=0,s2=0;
for(int j=0;j<m;++j){
s+=(M[i][j]*(-1));
s2+=M[i][j];
}
if(s>s2)
return 0;
return 1;
}
bool MaxC(int j,int M[17][17]){long long int s=0,s2=0;
for(int i=0;i<n;++i){
s+=(M[i][j]*(-1));
s2+=M[i][j];
}
if(s>s2)
return 0;
return 1;
}
long long int rez(int M[17][17]){long long int suma = 0;
for(int i=0;i<n;++i)
for(int j=0;j<m;++j)
suma+=M[i][j];
return suma;
}
long long int solveC(){
for(int j=0;j<m;++j)
if(MaxC(j,A)==0)
for(int i=0;i<n;++i)A[i][j]*=(-1);
for(int i=0;i<n;++i)
if (MaxL(i,A)==0)
for(int j=0;j<m;++j)A[i][j]*=(-1);
return rez(A);
}
long long int solveR(){
for(int i=0;i<n;++i)
if (MaxL(i,M)==0)
for(int j=0;j<m;++j)M[i][j]*=(-1);
for(int j=0;j<m;++j)
if(MaxC(j,M)==0)
for(int i=0;i<n;++i)M[i][j]*=(-1);
return rez(M);
}
void copiere(int M[17][17]){
for(int i=0;i<n;++i)
for(int j=0;j<m;++j)
A[i][j]=M[i][j];
}
int main()
{
fscanf(f,"%d%d",&n,&m);
for(int i=0; i<n; ++i)
for(int j=0; j<m; ++j)
fscanf(f,"%d",&M[i][j]);
copiere(M);
fprintf(g,"%lli",max(solveC(),solveR()));
return 0;
}
