Cod sursa(job #2788581)

Utilizator KOTerraStoica mihai KOTerra Data 25 octombrie 2021 22:54:43
Problema Plantatie Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");

int a[501][501];
int r[75001];

int wd[4] = { 1,0,-1,0 };
int hg[4] = { 0,1,0,-1 };

int main() {
	int n; int M;
	cin >> n>>M;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= M; i++) {
		int l, c, d;
		cin >> l >> c >> d;
		int maxi = 0;


		int dir = 0;
		int width = d, height = d;
		int lungW = 0, lungH = 0;

		while (width > d / 2 && height > d / 2) {

			lungW += wd[dir];
			lungH += hg[dir];

			int wi = l + lungW - 1;
			int hi = c + lungH - 1;

			if (a[wi][hi] >= maxi) {
				maxi = a[wi][hi];
			}

			switch (dir) {
			case 0: {
				if(lungW==width) {
					dir = 1;
					height--;
				}
				break;
			}
			case 1: {
				if (lungH == (d - height)) {
					dir = 2;
					width--;
				}
				break;
			}
			case 2: {
				if (lungW == (d - width)) {
					dir = 3;
					height--;
				}
				break;
			}
			case 3: {
				if (lungH == height) {
					dir = 0;
					width--;
				}
				break;
			}


			}

		}

		r[i] = maxi;
	}
	for (int i = 1; i <= M; i++) {
		cout << r[i]<<'\n';
	}
	
	return 0;
}