結果
| 問題 |
No.2786 RMQ on Grid Path
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-14 21:32:03 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,232 bytes |
| コンパイル時間 | 5,860 ms |
| コンパイル使用メモリ | 336,504 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-06-14 21:32:20 |
| 合計ジャッジ時間 | 15,279 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 TLE * 1 -- * 24 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a, T b)
{
if(a<b)
{
a = b;
return true;
}
return false;
}
template<class T> bool chmin(T &a, T b)
{
if(a>b)
{
a = b;
return true;
}
return false;
}
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};
int main()
{
int H, W;
cin >> H >> W;
auto in = [&](int h, int w) -> bool {
return (0<=h && h<H && 0<=w && w<W);
};
vector<vector<int>> A(H, vector<int>(W));
rep(i,H) rep(j,W) cin >> A[i][j];
int mx = 0;
rep(i,H) rep(j,W) chmax(mx, A[i][j]);
auto f = [&](int x, int a, int b, int c, int d) -> bool {
dsu uf(H*W);
rep(i,H) rep(j,W) if(A[i][j]<=x) rep(t,4)
{
int nh = i+dx[t];
int nw = j+dy[t];
if(in(nh,nw) && A[nh][nw]<=x) uf.merge(i*W+j, nh*W+nw);
}
return uf.same(a*W+b, c*W+d);
};
int Q;
cin >> Q;
while(Q--)
{
int a, b, c, d;
cin >> a >> b >> c >> d;
a--;
b--;
c--;
d--;
int l = max(A[a][b], A[c][d])-1;
int r = mx;
while(r-l>1)
{
int mid = (l+r)/2;
if(f(mid,a,b,c,d)) r = mid;
else l = mid;
}
cout << r << '\n';
}
}