結果
問題 | No.2855 Move on Grid |
ユーザー |
|
提出日時 | 2024-09-13 09:37:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 671 ms / 3,000 ms |
コード長 | 1,345 bytes |
コンパイル時間 | 2,330 ms |
コンパイル使用メモリ | 211,816 KB |
最終ジャッジ日時 | 2025-02-24 06:51:51 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)); priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> PQ; DP[0][0]=(A[0][0]<mid); PQ.push({DP[0][0],{0,0}}); vector<vector<bool>> seen(N,vector<bool>(M,0)); while(!PQ.empty()){ ll c=PQ.top().first; ll y=PQ.top().second.first; ll x=PQ.top().second.second; PQ.pop(); 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; PQ.push({nc,{ny,nx}}); } } if(DP[N-1][M-1]<=K)L=mid; else R=mid; } cout<<L<<endl; }