Cod sursa(job #2482240)

Utilizator cameliapatileaPatilea Catalina Camelia cameliapatilea Data 27 octombrie 2019 22:14:29
Problema Zone Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.78 kb
#include<iostream>
#include<fstream>
#include <algorithm>

using namespace std;
ifstream f("zone.in");
ofstream g("zone.out");
int n, v[20];
long long table[550][550];
long long poz[550][550];
pair<pair<int, int>, pair<int, int>> solutie[10005];
int linie, coloana, x, y;
int nr;
void citire()
{
    f >> n;
    for(int i = 1; i <= 9; i++)
        f >> v[i];
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++) {
            f >> table[i][j];
            poz[i][j] = poz[i - 1][j]  + poz[i][j-1];
            poz[i][j] = poz[i][j] - poz[i-1][j-1] + table[i][j];
        }
    }
}
bool check(long long number)
{
    for(int i = 1; i <= 9; i++)
        if(number == v[i])
            return true;
    return false;
}
void afisare()
{
    g << solutie[1].first.first << " " << solutie[1].second.first << " " << solutie[1].first.second << " " << solutie[1].second.second << '\n';
}
int main()
{
    citire();
    for(int i = 1; i<= n; i++)
    {
        for(int j = 1; j <= n; j++)
            if(check(poz[i][j]) != false)
            {
                 linie =  i;
                 coloana = j;
                for(int x = linie + 1; x <= n; x++)
                {
                    int temp = poz[x][j] - poz[i][j];
                    if(check(temp) != false)
                    {
                        for(int y = coloana + 1; y <= n; y++)
                        {
                            int temp1 = poz[linie][y]- poz[linie][coloana];
                            int temp2 = poz[linie][n] - poz[linie][y];
                            int temp3 = poz[x][y] - poz[x][coloana] - poz[linie][y] + poz[linie][coloana];
                            int temp4 = poz[x][n] - poz[x][y] - poz[linie][n] + poz[linie][y];
                            int temp5= poz[n][coloana] - poz[x][coloana];
                            int temp6 = poz[n][y] - poz[n][coloana] - poz[x][y] + poz[x][coloana];
                            int temp7 = poz[n][n] - poz[x][n] - poz[n][y] + poz[x][y];
                            if(check(temp1) != false && check(temp2) != false &&check(temp3) != false && check(temp4) != false && check(temp5) != false && check(temp6)!= false && check(temp7) != false)
                            {
                                            nr++;
                                            solutie[nr].first.first = linie;
                                            solutie[nr].first.second = coloana;
                                            solutie[nr].second.first = x;
                                            solutie[nr].second.second = y;
                                        }
                                    }
                                }
                            }

                        }
                    }

    sort(solutie + 1, solutie + nr + 1);
    afisare();
}