Răspuns :
#include <bits/stdc++.h>
using namespace std;
int n,m,k,i,j,p;
int main()
{
cin >> n >> m >> k;
int a[n+1][m+1];
for(int x=1;x<=n;x++) //Creeam o matrice complet din zerouri
for(int y=1;y<=m;y++)
a[x][y]=0;
for(int x=1;x<=k;x++)
cin >> i >> j >> p, a[i][j]=p; //Punem camerele
for(int y=1;y<=n;y++)
{
for(int x=1;x<=m;x++)
if(a[y][x]!=0 and a[y][x]!=-1) //Controlam daca am dat de o camera
{
int k=1;
while(k<=a[y][x]-1) //Cream un while care va repeta structura de p-1(a[y][x]-1) ori
{
if(y+k<=n and x+k<=m and a[y+k][x+k]==0) a[y+k][x+k]=-1; //Controlam daca nu iesim din matrice si daca nu dam de o camera!!! Daca nu punem -1
if(y+k<=n and x-k>=1 and a[y+k][x-k]==0) a[y+k][x-k]=-1;
if(y-k>=1 and x+k<=m and a[y-k][x+k]==0) a[y-k][x+k]=-1;
if(y-k>=1 and x-k>=1 and a[y-k][x-k]==0) a[y-k][x-k]=-1;
k++;
}
}
}
int S=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i][j]==0) S++; //Controlam cite zone cu 0 au ramas
cout << S; //Afisam
return 0;
}
using namespace std;
int n,m,k,i,j,p;
int main()
{
cin >> n >> m >> k;
int a[n+1][m+1];
for(int x=1;x<=n;x++) //Creeam o matrice complet din zerouri
for(int y=1;y<=m;y++)
a[x][y]=0;
for(int x=1;x<=k;x++)
cin >> i >> j >> p, a[i][j]=p; //Punem camerele
for(int y=1;y<=n;y++)
{
for(int x=1;x<=m;x++)
if(a[y][x]!=0 and a[y][x]!=-1) //Controlam daca am dat de o camera
{
int k=1;
while(k<=a[y][x]-1) //Cream un while care va repeta structura de p-1(a[y][x]-1) ori
{
if(y+k<=n and x+k<=m and a[y+k][x+k]==0) a[y+k][x+k]=-1; //Controlam daca nu iesim din matrice si daca nu dam de o camera!!! Daca nu punem -1
if(y+k<=n and x-k>=1 and a[y+k][x-k]==0) a[y+k][x-k]=-1;
if(y-k>=1 and x+k<=m and a[y-k][x+k]==0) a[y-k][x+k]=-1;
if(y-k>=1 and x-k>=1 and a[y-k][x-k]==0) a[y-k][x-k]=-1;
k++;
}
}
}
int S=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i][j]==0) S++; //Controlam cite zone cu 0 au ramas
cout << S; //Afisam
return 0;
}