結果
| 問題 |
No.2786 RMQ on Grid Path
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-30 20:09:10 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,572 bytes |
| コンパイル時間 | 5,672 ms |
| コンパイル使用メモリ | 317,744 KB |
| 実行使用メモリ | 13,888 KB |
| 最終ジャッジ日時 | 2024-08-30 20:09:29 |
| 合計ジャッジ時間 | 18,235 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 TLE * 1 -- * 24 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
using ld = long double;
using mint = atcoder::modint1000000007;
const ll inf = 9e18;
bool in_out(ll x,ll y,ll h,ll w){
return 0<=x and x<h and 0<=y and y<w;
}
ll di[8]={1,-1,0,0,1,1,-1,-1};
ll dj[8]={0,0,1,-1,1,-1,-1,1};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
ll h,w;
cin >> h >> w;
vector a(h,vector<ll>(w));
for(ll i=0;i<h;i++){
for(ll j=0;j<w;j++){
cin >> a[i][j];
}
}
ll Q;
cin >> Q;
while(Q--){
ll si,sj,gi,gj;
cin >> si >> sj >> gi >> gj;
si--;sj--;gi--;gj--;
ll ok=h*w+1,ng=0;
while(ok-ng>1){
ll x=(ok+ng)/2;
vector vis(h,vector<bool>(w,false));
if(a[si][sj]<=x){
vis[si][sj]=true;
queue<pair<ll,ll>> q;
q.push({si,sj});
while(q.size()){
auto[i,j]=q.front();
q.pop();
for(ll d=0;d<4;d++){
ll ni=i+di[d];
ll nj=j+dj[d];
if(in_out(ni,nj,h,w)==false) continue;
if(a[ni][nj]>x) continue;
if(vis[ni][nj]==true) continue;
vis[ni][nj]=true;
q.push({ni,nj});
}
}
}
if(vis[gi][gj]==false) ng=x;
else ok=x;
}
cout << ok << endl;
}
}