122612024-12-10 17:56:12IgnácHegyi levegőcpp17Wrong answer 0/1003.118s293348 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(res[a-1][b-1], res[c-1][d-1])) << '\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Wrong answer1ms320 KiB
subtask20/19
3Wrong answer6ms320 KiB
4Time limit exceeded3.105s98840 KiB
5Wrong answer2.625s49768 KiB
6Wrong answer103ms3568 KiB
7Time limit exceeded3.118s293348 KiB
8Wrong answer1.049s25224 KiB
9Wrong answer74ms1964 KiB
10Wrong answer6ms1016 KiB
subtask30/20
11Accepted1ms320 KiB
12Wrong answer4ms508 KiB
13Wrong answer28ms568 KiB
14Wrong answer293ms2480 KiB
15Wrong answer771ms8260 KiB
subtask40/20
16Wrong answer670ms6992 KiB
17Wrong answer805ms59192 KiB
18Time limit exceeded3.085s201588 KiB
19Time limit exceeded3.088s201440 KiB
20Time limit exceeded3.101s201412 KiB
subtask50/31
21Wrong answer615ms17208 KiB
22Time limit exceeded3.091s99644 KiB
23Time limit exceeded3.105s271080 KiB
24Time limit exceeded3.101s198084 KiB
25Wrong answer531ms3508 KiB
26Time limit exceeded3.098s198336 KiB
27Time limit exceeded3.101s198236 KiB
28Wrong answer527ms3620 KiB
29Time limit exceeded3.098s2340 KiB
subtask60/10
30Wrong answer1.786s73500 KiB
31Time limit exceeded3.088s103016 KiB
32Time limit exceeded3.092s201416 KiB
33Time limit exceeded3.091s201432 KiB
34Wrong answer1.509s11160 KiB
35Time limit exceeded3.082s7096 KiB
36Time limit exceeded3.096s201404 KiB
37Time limit exceeded3.111s201408 KiB
38Wrong answer1.483s11672 KiB
39Time limit exceeded3.082s9060 KiB