Head office building CodeChef Solution

Problem -Head office building CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.
<<Previous CodeChef Problem Next Codechef Problem>>

Head office building CodeChef Solution in C++14

#include<bits/stdc++.h>
using namespace std;
const int N = 200005;
bool v[3005][3005];
int sum[3005][3005];
int n,m,d,t,x[N],y[N],c[N],ans = 2e9;
int main(){
	scanf("%d%d%d%d",&n,&m,&d,&t);
	for(int i = 0;i <= n;i++)
		for(int j = 0;j <= m;j++)
			v[i - j + 1001][i + j + 1001] = 1;
	for(int i = 1;i <= t;i++){
		scanf("%d%d%d",&x[i],&y[i],&c[i]);
		int a = x[i],b = y[i];
		x[i] = a - b,y[i] = a + b;
		sum[x[i] + 1001][y[i] + 1001] = c[i];
	}
	for(int i = 1;i <= 3000;i++){
		for(int j = 1;j <= 3000;j++){
			sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		}
	}
	d *= 2;
	for(int i = 1;i + d <= 3000;i++){
		for(int j = 1;j + d <= 3000;j++){
			if(!v[i][j] || !v[i][j + d] || !v[i + d][j] || !v[i + d][j + d])continue;
			ans = min(ans,sum[i + d][j + d] - sum[i + d][j - 1] - sum[i - 1][j + d] + sum[i - 1][j - 1]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Head office building CodeChef Solution in C

#include <stdio.h>
#define min(a,b) ((a<b)?(a):(b))

int w, h, n, d, X[4][1010][1010];

inline int f1(int x, int y)
{
if(x>=0&&x<=w&&y>=0&&y<=h) return X[1][x][y];
return 0;
}

inline int f2(int x, int y)
{
if(x>=0&&x<=w&&y>=0&&y<=h) return X[0][x][y];
return 0;
}

inline int f3(int x, int y)
{
if(x>=0&&x<=w&&y>=0&&y<=h) return X[2][x][y];
return 0;
}

main()
{
int x, y, c, i, res;
for(i=!scanf("%d %d %d %d",&w,&h,&d,&n); ++i<=n; scanf("%d %d",&x,&y),scanf("%d",&X[0][x][y]));
for(y=0; y<=h; y++)
	for(x=-1; ++x<=w; X[1][x][y]=f1(x-1,y-1)-f2(x-d-1,y-d-1)+X[0][x][y],X[2][x][y]=f3(x+1,y-1)-f2(x+d+1,y-d-1)+X[0][x][y]);
for(y=d; y>=0; y--)
	for(x=y-d; x<=d-y; X[3][d][d]+=X[0][d+x++][d+y]);
for(y=-1; y>=-d; y--)
	for(x=(-y-d); x<=(d+y); X[3][d][d]+=X[0][d+x++][d+y]);
for(x=d+1,res=X[3][d][d]; x+d<=w; res=min(res,(X[3][x][d]=X[3][x-1][d]-(X[1][x-1][2*d]+X[2][x-d-1][d]-X[0][x-d-1][d])+(X[2][x][2*d]+X[1][x+d][d]-X[0][x+d][d]))),x++);
for(y=d+1; y+d<=h; y++)
	for(x=d; x+d<=w; res=min(res,(X[3][x][y]=X[3][x][y-1]-(X[2][x-d][y-1]+X[1][x+d][y-1]-X[0][x][y-d-1])+(X[1][x][y+d]+X[2][x][y+d]-X[0][x][y+d]))),x++);
printf("%d",res);
return 0;
}
Head office building CodeChef Solution Review:

In our experience, we suggest you solve this Head office building CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Head office building CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Head office building CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *