Cod sursa(job #2833448)

Utilizator ana_nosaAnamaria Nosa ana_nosa Data 15 ianuarie 2022 11:11:17
Problema Zone Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.41 kb
#include<fstream>
#include<algorithm>
using namespace std;
int N;
int viz[11], A[600][600];;
long long matr[600][600], M[11];
int L[5], C[5];
inline int ExistaInVector(long long x)
{  for(int i=1;i<=9;i++)
      if(!viz[i] && M[i]==x)
         return i;
    return 0;
}
inline bool EsteBunaDistribuirea(int l1,int l2,int c1,int c2)
{  int i,j,a;
   L[1]=l1; L[2]=l2; L[3]=C[3]=N;
   C[1]=c1; C[2]=c2;
   for(i=1;i<=3;i++)
      for(j=1;j<=3;j++) {
         a=ExistaInVector(matr[L[i]][C[j]]+matr[L[i-1]][C[j-1]]-matr[L[i-1]][C[j]]-matr[L[i]][C[j-1]]);
	 if(!a || viz[a]) return false;
         viz[a]=1;
      }
   return true;
}
void Rezolvare()
{  int i,j,k,l,ii,gata=0;
    for(i=1;i<N && !gata;i++)
        for(j=1;j<N && !gata;j++)
            if(ExistaInVector(matr[i][j]))
                for(k=i+1;k<N && !gata;k++)
                    for(l=j+1;l<N && !gata;l++) {
                       gata=EsteBunaDistribuirea(i,k,j,l);
                       for(ii=1;ii<=9;ii++) viz[ii]=0;
                    }
}
int main()
{  ifstream fi("zone.in"); ofstream fo("zone.out");
   int i,j;
   fi>>N;
   for(i=1;i<=9;i++) fi>>M[i];
   sort(M+1, M+10);
   for(i=1;i<=N;i++)
      for(j=1;j<=N;j++) fi>>A[i][j];
   for(i=1;i<=N;i++)
      for(j=1;j<=N;j++)
         matr[i][j]=A[i][j]+matr[i-1][j]+matr[i][j-1]-matr[i-1][j-1];
    Rezolvare();
    fo<<L[1]<<" " <<L[2]<<" "<<C[1]<<" "<<C[2]<<"\n";
}