Cod sursa(job #1528270)
Utilizator | Data | 19 noiembrie 2015 13:44:10 | |
---|---|---|---|
Problema | Zone | Scor | 80 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 3.71 kb |
#include<stdio.h>
#include<algorithm>
using namespace std;
long n,b[10],m[520][520],sp[520][520],c1,c2,l1,l2,c1l1,sume[10];
long check(long a)
{
for(long i=1; i<=9; ++i) if(b[i]==a) return i;
return 0;
}
long val(long a,long b,long x,long y)
{
return sp[x][y]+sp[a-1][b-1]-sp[x][b-1]-sp[a-1][y];
}
long one()
{
return val(1,1,l1,c1);
}
long two()
{
return val(1,c1+1,l1,c2);
}
long three()
{
return val(1,c2+1,l1,n);
}
long four()
{
return val(l1+1,1,l2,c1);
}
long five()
{
return val(l1+1,c1+1,l2,c2);
}
long six()
{
return val(l1+1,c2+1,l2,n);
}
long seven()
{
return val(l2+1,1,n,c1);
}
long eight()
{
return val(l2+1,c1+1,n,c2);
}
long nine()
{
return val(l2+1,c2+1,n,n);
}
int main()
{
freopen("zone.in","r",stdin);
freopen("zone.out","w",stdout);
scanf("%d",&n);
for(long i=1; i<=9; ++i) scanf("%d",&b[i]);
sort(b+1,b+10);
for(long i=1; i<=n; ++i)
for(long j=1; j<=n; ++j) scanf("%d",&m[i][j]);
sp[1][1]=m[1][1];
for(long j=2; j<=n; ++j) sp[j][1]=sp[j-1][1]+m[j][1];
for(long i=2; i<=n; ++i) sp[1][i]=sp[1][i-1]+m[1][i];
for(long i=1; i<=n; i++)
for(long j=2; j<=n; j++) sp[i][j]=sp[i-1][j]+sp[i][j-1]+m[i][j]-sp[i-1][j-1];
for(long i=1; i<n; ++i)
for(long j=1; j<n; ++j)
{
l1=i;
c1=j;
sume[1]=one();
if(!check(one())) continue;
{
for(long k=i+1; k<n; ++k)
{
c2=0;
l2=k;
if(!check(four())) continue;
if(!check(seven())) continue;
sume[4]=four();
sume[7]=seven();
for(long l=j+1; l<n; ++l)
{
c2=l;
if(!check(two()))
{
c2=0;
continue;
}
if(!check(three()))
{
c2=0;
continue;
}
if(!check(five()))
{
c2=0;
continue;
}
if(!check(six()))
{
c2=0;
continue;
}
if(!check(eight()))
{
c2=0;
continue;
}
if(!check(nine()))
{
c2=0;
continue;
}
sume[1]=one();
sume[2]=two();
sume[3]=three();
sume[4]=four();
sume[5]=five();
sume[6]=six();
sume[7]=seven();
sume[8]=eight();
sume[9]=nine();
//return nine();
sort(sume+1,sume+10);
//if(c2==0)
{
c2=l;
printf("%d %d %d %d",l1,l2,c1,c2);
return 0;
}
}
}
}
}
l1=1;
l2=3;
c1=2;
c2=3;
return 0;
///printf("%d %d %d %d %d %d %d %d %d",,,,,,,,,;
}