結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-13 09:39:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 172 ms / 3,000 ms |
| コード長 | 1,354 bytes |
| コンパイル時間 | 2,188 ms |
| コンパイル使用メモリ | 212,176 KB |
| 最終ジャッジ日時 | 2025-02-24 06:52:06 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll N,M,K;
cin>>N>>M>>K;
vector<vector<ll>> A(N,vector<ll>(M));
for(int i=0;i<N;i++)for(int j=0;j<M;j++)cin>>A[i][j];
ll L=0,R=1e9+1;
while(R-L>1){
ll mid=(R+L)/2;
vector<vector<ll>> DP(N,vector<ll>(M,1e9));
deque<pair<ll,pair<int,int>>> PQ;
DP[0][0]=(A[0][0]<mid);
PQ.push_back({DP[0][0],{0,0}});
vector<vector<bool>> seen(N,vector<bool>(M,0));
while(!PQ.empty()){
ll c=PQ.front().first;
ll y=PQ.front().second.first;
ll x=PQ.front().second.second;
PQ.pop_front();
if(seen[y][x])continue;
seen[y][x]=1;
for(int d=0;d<4;d++){
int ny=y+dy[d];
int nx=x+dx[d];
if(ny<0||nx<0||ny>=N||nx>=M)continue;
if(seen[ny][nx])continue;
ll nc=c+(A[ny][nx]<mid);
if(DP[ny][nx]<=nc)continue;
DP[ny][nx]=nc;
if(nc==c)PQ.push_front({nc,{ny,nx}});
else PQ.push_back({nc,{ny,nx}});
}
}
if(DP[N-1][M-1]<=K)L=mid;
else R=mid;
}
cout<<L<<endl;
}