## 1767 - Funny Areas

Discussion around the problems of the COJ.
Forum rules
Remember that posting AC code is not allowed here. If you are going to ask a question or to post a solution, describe your algorithm instead. Posting AC code will be penalized.
ymondelo20
Posts: 1968
Joined: 9 years ago
Location: Universidad de las Ciencias Informáticas
Gender: Contact:

### 1767 - Funny Areas

"Every problem has a simple, fast and wrong solution" OJ's Main Law. Phantom
Posts: 58
Joined: 8 years ago
Location: Cuba
Gender: ### Re: 1767 - Funny Areas

I got only WA in this problem, and I proved it even with negatives values in the center. I cannot understand…. Who is wrong, the COJ or me?? Can anybody help me?
This is my code in C++(is not AC):

Code: Select all

``````#include <cstdlib>
#include <iostream>

using namespace std;
int max(int, int);
int min(int, int);

int main()
{
int dimX, dimY, cases;
cin>>dimX>>dimY;
int matrix[dimX][dimY];
for(int i=0; i<dimX; i++)
for(int j=0; j<dimY; j++)cin>>matrix[i][j];
cin>>cases;
int info, suma;
for(int k=0; k<cases; k++)
{
cin>>info>>info>>info;
suma = 0;
int lim = {max(0,info-info), min(dimX-1,info+info),
max(0,info-info), min(dimY-1,info+info)};
for(int i=lim; i<=lim; i++)
for(int j=lim; j<=lim; j++)
if(abs(info-i) + abs(info-j) <= info)
suma += matrix[i][j];
cout<<suma<<'\n';
}
return 0;
}

int max(int a, int b){return (a > b)? a : b;}
int min(int a, int b){return (a < b)? a : b;}
``````
I prevent in “lim” the out of range cases. Thanks to “lim”, I only see the cases that are in range of the radius and in range of the matrix.
After, I go over the square that describe “lim”, and if the value are in the range of the radius, I sum the value in this position (suma += matrix[j] You see?? Very simple.