結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2024-08-25 14:20:04 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,511 bytes |
| コンパイル時間 | 3,262 ms |
| コンパイル使用メモリ | 257,576 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-08-25 14:21:28 |
| 合計ジャッジ時間 | 72,299 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 TLE * 12 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
int dh[]={1,0,-1,0};
int dw[]={0,1,0,-1};
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n,m,k;
cin>>n>>m>>k;
VV<ll> A(n,V<ll>(m));
rep(i,n) rep(j,m) cin>>A[i][j];
ll ok=0,ng=1e9+1;
while(ng-ok>1){
ll mid=(ok+ng)/2;
VV<ll> B(n,V<ll>(m)),dis(n,V<ll>(m,-1));
rep(i,n) rep(j,m){
if(A[i][j]<mid) B[i][j]=1;
}
dis[0][0]=0;
if(B[0][0]) dis[0][0]=1;
queue<pair<int,int>> que;
que.push({0,0});
while(que.size()){
auto a=que.front(); que.pop();
int i=a.first,j=a.second;
rep(k,4){
int ni=i+dh[k],nj=j+dw[k];
if(ni<0 || nj<0 || ni>=n || nj>=m) continue;
if(B[ni][nj]){
if(dis[ni][nj]==-1){
dis[ni][nj]=dis[i][j]+1;
que.push({ni,nj});
}
else if(dis[ni][nj]>dis[i][j]+1){
dis[ni][nj]=dis[i][j]+1;
que.push({ni,nj});
}
}
else{
if(dis[ni][nj]==-1){
dis[ni][nj]=dis[i][j];
que.push({ni,nj});
}
else if(dis[ni][nj]>dis[i][j]){
dis[ni][nj]=dis[i][j];
que.push({ni,nj});
}
}
}
}
if(dis[n-1][m-1]<=k) ok=mid;
else ng=mid;
}
cout<<ok<<endl;
return 0;
}
umezo