122622024-12-10 18:01:39IgnácHegyi levegőcpp17Wrong answer 0/1003.115s287736 KiB
#include<bits/stdc++.h>
using namespace std;

int main(){
	int n, m, qn;
	cin >> n >> m >> qn;
	vector<vector<int>> h(n, vector<int>(m));
	int mini=INT_MAX;
	for(vector<int>& x : h){
		for(int& y : x){
			cin >> y;
			mini=min(mini, y);
		}
	}
	vector<vector<int>> res(n, vector<int>(m, INT_MAX));
	priority_queue<array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>>> pq;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(h[i][j]==mini){ pq.push({h[i][j], i, j}); mini=INT_MIN;}
		}
	}
	while(!pq.empty()){
		auto [v, x, y]=pq.top();
		pq.pop();
		res[x][y]=v;
		if(0<x && res[x-1][y]==INT_MAX) pq.push({max(v, h[x-1][y]), x-1, y});
		if(x+1<n && res[x+1][y]==INT_MAX) pq.push({max(v, h[x+1][y]), x+1, y});
		if(0<y && res[x][y-1]==INT_MAX) pq.push({max(v, h[x][y-1]), x, y-1});
		if(y+1<m && res[x][y+1]==INT_MAX) pq.push({max(v, h[x][y+1]), x, y+1});
	}
	for(int i=0;i<qn;i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		//cout << h[a-1][b-1] << ' ' << res[a-1][b-1] << ' ' << res[c-1][d-1] << '\n';
		cout << max(h[a-1][b-1], max(h[c-1][d-1], max(res[a-1][b-1], res[c-1][d-1]))) << '\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Wrong answer1ms320 KiB
subtask20/19
3Wrong answer4ms436 KiB
4Time limit exceeded3.107s98876 KiB
5Wrong answer2.513s49604 KiB
6Wrong answer103ms3660 KiB
7Time limit exceeded3.115s197428 KiB
8Wrong answer1.047s25216 KiB
9Wrong answer74ms1964 KiB
10Wrong answer6ms824 KiB
subtask30/20
11Accepted1ms320 KiB
12Wrong answer3ms500 KiB
13Wrong answer28ms480 KiB
14Wrong answer287ms2348 KiB
15Wrong answer713ms8264 KiB
subtask40/20
16Wrong answer647ms7056 KiB
17Wrong answer794ms55864 KiB
18Time limit exceeded3.092s201692 KiB
19Time limit exceeded3.095s201420 KiB
20Time limit exceeded3.102s201424 KiB
subtask50/31
21Wrong answer570ms13376 KiB
22Time limit exceeded3.085s99660 KiB
23Time limit exceeded3.098s287736 KiB
24Time limit exceeded3.095s198312 KiB
25Wrong answer518ms3512 KiB
26Time limit exceeded3.089s198336 KiB
27Time limit exceeded3.096s198324 KiB
28Wrong answer517ms3620 KiB
29Time limit exceeded3.098s2164 KiB
subtask60/10
30Wrong answer1.71s60212 KiB
31Time limit exceeded3.082s103272 KiB
32Time limit exceeded3.085s201440 KiB
33Time limit exceeded3.086s201412 KiB
34Wrong answer1.465s11180 KiB
35Time limit exceeded3.086s7008 KiB
36Time limit exceeded3.098s201196 KiB
37Time limit exceeded3.101s201392 KiB
38Wrong answer1.476s11664 KiB
39Time limit exceeded3.085s9056 KiB