Cod sursa(job #2088263)

Utilizator Consti.001FMI Dranca Constantin Consti.001 Data 14 decembrie 2017 21:37:24
Problema A+B Scor 0
Compilator cpp Status done
Runda Lista lui wefgef Marime 1.67 kb
#include<fstream>
#include<iostream>
#include<algorithm>

using namespace std;
ifstream f("data.in");
ofstream g("data.out");


int main()
{
    int n,m,k;
    f>>n>>m;
    int mat[n][m];
    int mat_count[n][m];
    for(int i=0;i<n;++i)
    for(int j=0;j<m;++j)
    {f>>mat[i][j]; mat_count[i][j]=0;}
    f>>k;
    int squares_number=0;
    int line=-3,col=-3,maxi=0;
    for(int i=0;i<n;++i)
    {
        mat_count[0][i]=(mat[0][i]+1)%2;
        if((mat_count[0][i]-k+1)>0)
        squares_number+=mat_count[0][i]-k+1;
        if(maxi<mat_count[0][i])
        {
            maxi=mat_count[0][i];
            line =0;
            col=i;
        }
    }
    for(int i=1;i<n;++i)
    {
        mat_count[i][0]=(mat[i][0]+1)%2;
        if((mat_count[i][0]-k+1)>0)
        squares_number+=mat_count[i][0]-k+1;


        if(maxi<mat_count[i][0])
        {
            maxi=mat_count[i][0];
            line =i;
            col=0;
        }

        for(int j=1;j<m;++j)
        if(mat[i][j]==0)
        {
            mat_count[i][j]=min(mat_count[i][j-1],min(mat_count[i-1][j-1],mat_count[i-1][j]))+1;
            if((mat_count[i][j]-k+1)>0)
            squares_number+=mat_count[i][j]-k+1;

            if(maxi<mat_count[i][j])
                {
                    maxi=mat_count[i][j];
                    line =i;
                    col=j;
                }
        }
        else
        mat_count[i][j]=0;
    }
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<m;++j)
        g<<mat_count[i][j]<<" ";
        g<<"\n";
    }

    g<<maxi<<"\n";
    g<<line-maxi+2<<" "<<col-maxi+2<<"\n";
    g<<squares_number;
    return 0;
}